HTTP Status 404 - Not Found - with Spring, Hibernate, Jpa, Mysql eTomcat

Asked

Viewed 62 times

-1

I made a change in my project passing the responsibility to Spring to control the transactions according to Caelum documentation and other examples I searched the web, already searched for information on google, books, tutors, etc... apparently the project is correct, but for some reason he can’t find the mapped classes, and ends up bringing a 404 error page, as image:enter image Description here

then my web.xml settings:

    <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
    <display-name>projetoLoja</display-name>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>                
    <servlet>
        <servlet-name>spring mvc</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:applicationContext.xml</param-value>
        </init-param>
         <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring mvc</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>30</session-timeout>
    </session-config>  
    <filter>
         <filter-name>SetCharacterEncodingFilter</filter-name>
         <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
         <init-param>
             <param-name>encoding</param-name>
             <param-value>UTF8</param-value>
         </init-param>
         <init-param>
             <param-name>forceEncoding</param-name>
             <param-value>true</param-value>
         </init-param>
    </filter>
    <filter-mapping>
        <filter-name>SetCharacterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>  

</web-app>

my applicationContext.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:mvc="http://www.springframework.org/schema/mvc"
        xmlns:tx="http://www.springframework.org/schema/tx"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
                            http://www.springframework.org/schema/beans/spring-beans.xsd
                            http://www.springframework.org/schema/context
                            http://www.springframework.org/schema/context/spring-context.xsd
                            http://www.springframework.org/schema/mvc
                            http://www.springframework.org/schema/mvc/spring-mvc.xsd
                            http://www.springframework.org/schema/tx
                            http://www.springframework.org/schema/tx/spring-tx.xsd
                            ">

    <context:component-scan base-package="br.com.loja.projetoloja" />
    <mvc:annotation-driven />
    <mvc:default-servlet-handler/>    
    <mvc:interceptors>
        <bean class="br.com.loja.projetoloja.interceptor.AutorizadorInterceptor"></bean>
    </mvc:interceptors>
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/"/>
        <property name="suffix" value=".jsp"/>
        <!-- <property name="exposeContext" value="true"/> -->
    </bean>


    <bean id="mysqlDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>

        <!-- local --> 
        <property name="url" value="jdbc:mysql://localhost/banco?autoReconnect=true"/>
        <property name="username" value="root"/>
        <property name="password" value="xxxxx"/>
        <property name="validationQuery" value="SELECT 1"/>
        <property name="testOnBorrow" value="true"/>

    </bean> 

    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceUnitName" value="mysql" />
        <property name="dataSource" ref="mysqlDataSource" />        
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
        </property>
    </bean>  

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>  

    <tx:annotation-driven />

</beans>

my persistence.xml file:

http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0">

<persistence-unit name="mysql" transaction-type="RESOURCE_LOCAL">

    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>

    <class>br.com.loja.projetoloja.modelo.Contato</class>
    <class>br.com.loja.projetoloja.modelo.Usuario</class>
    <class>br.com.loja.projetoloja.modelo.Veiculo</class>
    <class>br.com.loja.projetoloja.modelo.Pessoa</class>
    <class>br.com.loja.projetoloja.modelo.Marca</class>
    <class>br.com.loja.projetoloja.modelo.Modelo</class>
    <class>br.com.loja.projetoloja.modelo.Versao</class>
    <class>br.com.loja.projetoloja.modelo.Venda</class>
    <class>br.com.loja.projetoloja.modelo.Compra</class>
    <class>br.com.loja.projetoloja.modelo.Contasapagar</class>
    <class>br.com.loja.projetoloja.modelo.Logs</class>
    <class>br.com.loja.projetoloja.modelo.ContasPagasePagar</class>

    <properties>                    
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>                                                           
        <property name="hibernate.show_sql" value="true" />
        <property name="hibernate.format_sql" value="true" />                                                           
    </properties>
</persistence-unit>

console error:

2020-03-09 08:56:08 DEBUG Dispatcherservlet:863 - Dispatcherservlet with name 'spring mvc' Processing GET request for [/projectLoja/listapessoas] 2020-03-09 08:56:08 DEBUG Requestmappinghandlermapping:301 - Looking up Handler method for path /listings 2020-03-09 08:56:08 DEBUG Requestmappinghandlermapping:311 - Did not find Handler method for [/list persons] 2020-03-09 08:56:08 DEBUG Simpleurlhandlermapping:191 - Matching Patterns for request [/listapessoa] are [/**] 2020-03-09 08:56:08 DEBUG Simpleurlhandlermapping:220 - URI Template variables for request [/listpersons] are {} 2020-03-09 08:56:08 DEBUG Simpleurlhandlermapping:141 - Mapping [/listapessoas] to Handlerexecutionchain with Handler [org.springframework.web.servlet.Resource.Defaultservlethttprequesthandler@35646544] and 1 Interceptor 2020-03-09 08:56:08 DEBUG Dispatcherservlet:949 - Last-Modified value for [/projectLoja/listapessoas] is: -1 2020-03-09 08:56:08 DEBUG Dispatcherservlet:1036 - Null Modelandview returned to Dispatcherservlet with name 'spring mvc': assuming Handleradapter completed request Handling 2020-03-09 08:56:08 DEBUG Dispatcherservlet:997 - Successfully completed request

example of a chunk of a controller class:

@Transactional
@Controller
public class PessoaController  extends HttpServlet{

    @Autowired
    PessoaDaoI daopessoa;

    @RequestMapping(value = "/listapessoas", method = RequestMethod.GET)
    public String lista(Model model) {
        //PessoaDao dao = new PessoaDao();
        model.addAttribute("pessoas", daopessoa.lista());
        //model.addAttribute("pessoas", dao.listaPessoas());
        return "listapessoas";
    }   

Follows a folder architecture:

enter image Description here

I hope I have been clear in my statements, I very much hope that you will help me!!

1 answer

0

Good evening, after much rss cost (already days ago) I managed to solve... and it was a very silly change.

trade in

public class PessoaController extends HttpServlet{

for

public class PessoaController{

Browser other questions tagged

You are not signed in. Login or sign up in order to post.