I can not save to the database in a Spring MVC project

2

I'm going to explain the project because I believe that most people usually create the projects using XML, and I created the Spring MVC project by dismissing the files that configure the project as XML.

The problem with my project is that I created the connection to the database, created the DAO methods, created the forms in the JSP and even then I can not insert the records into the database.

Well, I'll start explaining the project;

This is the class JPAConfiguration , which makes the connection to the database by dismissing the file persistence.xml :

@EnableTransactionManagement
public class JPAConfiguration {



      @Bean
       public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) {
          LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
          em.setDataSource(dataSource);
          em.setPackagesToScan(new String[] { "br.com.casadocodigo.loja.models" });

          JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
          em.setJpaVendorAdapter(vendorAdapter);
          em.setJpaProperties(additionalProperties());

          return em;
       }

       @Bean       
       public DataSource dataSource(Environment environment){
          DriverManagerDataSource dataSource = new DriverManagerDataSource();
          dataSource.setDriverClassName("com.mysql.jdbc.Driver");
          dataSource.setUrl("jdbc:mysql://localhost:3306/casadocodigo");
          dataSource.setUsername( "root" );
          dataSource.setPassword( "123" );
          return dataSource;
       }

       @Bean
       public PlatformTransactionManager transactionManager(EntityManagerFactory emf){
          JpaTransactionManager transactionManager = new JpaTransactionManager();
          transactionManager.setEntityManagerFactory(emf);   
          return transactionManager;
       }

       @Bean
       public PersistenceExceptionTranslationPostProcessor exceptionTranslation(){
          return new PersistenceExceptionTranslationPostProcessor();
       }

      Properties additionalProperties() {
          Properties properties = new Properties();
          properties.setProperty("hibernate.hbm2ddl.auto", "update");
          properties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
          properties.setProperty("hibernate.show_sql", "true");
          return properties;
       }

In this class above I believe I have no problem.

NOTE: I'm following a codebook that teaches Spring MVC. This logic I took from the book, because I'm a beginner as a Spring MVC programmer.

This is the class is ServletSpringMVC , it determines how the project mapping configuration will be.

public class ServletSpringMVC extends AbstractAnnotationConfigDispatcherServletInitializer {

    @Override
    protected Class<?>[] getRootConfigClasses() {
        // TODO Auto-generated method stub
        return new Class[]{AppWebConfiguration.class, JPAConfiguration.class};
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    protected String[] getServletMappings() {
        // TODO Auto-generated method stub
        return new String[]{"/"};
    }

This class below indicates where the mapping of JSP pages is;

@EnableWebMvc
@ComponentScan(basePackageClasses={HomeController.class, ProductDAO.class})
public class AppWebConfiguration extends WebMvcConfigurerAdapter{




    @Bean
    public InternalResourceViewResolver internalResourceViewResolver() {
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("/WEB-INF/views/");
        resolver.setSuffix(".jsp");
        return resolver;
    }

This is a simple DAO class:

@Repository
public class ProductDAO {

    @PersistenceContext
    private EntityManager manager;


    public void save(Product product) {
        manager.persist(product);       
    }

}

This is my entity:

@Entity
public class Product {

    @Id
    @GeneratedValue(strategy= GenerationType.IDENTITY)
    private Long id;
    private String title;
    @Lob
    private String description;
    private int pages;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public int getPages() {
        return pages;
    }

    public void setPages(int pages) {
        this.pages = pages;
    }

}

Very simple!

My project structure:

MypagethatI'mtryingtosaveproductsto:

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Cadastro de Produtos</title> </head> <body> <form method="post" action="/casadocodigo/produtos" > <div> <label for="title">Titulo</label> <input type="text" name="title" id="title" /> </div> <div> <label for="description">Descrição</label> <textarea rows="10" cols="20" name="description" id="description"></textarea> </div> <div> <label for="pages">Número de Paginas</label> <input type="text" name="pages" id="pages"/> </div> <div> <input type="submit" value="Enviar"/> </div> </form> </body> </html>

This is my page:

WhenItrytosave,itgives404error.Despitetheerror,IverifythateventhoughIgeneratedtheerror,itwasabletosave,butIstilldidnotsucceed.

OBS:Itonlygeneratesanerroronthepage,butdoesnotreportanerrorintheeclipseconsole.

IbelieveIhavedoneeverythingright,butitmaybethatIhavedonesomethingwrong,andIneedalotofhelptoknowwhereIamgoingwrong.

Cananyoneseesomethingwrongwiththecode?

Hereismyrepository:

link

Error:

///////////////////////////////////////////////////////////////////////////////

ATUALIZAÇÃODAPOSTAGEM

messagedisplayedbylog4j;

08:48:40[localhost-startStop-1]ContextLoader-RootWebApplicationContext:initializationstarted08:48:40[localhost-startStop-1]StandardServletEnvironment-Adding[servletConfigInitParams]PropertySourcewithlowestsearchprecedence08:48:40[localhost-startStop-1]StandardServletEnvironment-Adding[servletContextInitParams]PropertySourcewithlowestsearchprecedence08:48:40[localhost-startStop-1]StandardServletEnvironment-Adding[jndiProperties]PropertySourcewithlowestsearchprecedence08:48:40[localhost-startStop-1]StandardServletEnvironment-Adding[systemProperties]PropertySourcewithlowestsearchprecedence08:48:40[localhost-startStop-1]StandardServletEnvironment-Adding[systemEnvironment]PropertySourcewithlowestsearchprecedence08:48:40[localhost-startStop-1]StandardServletEnvironment-InitializedStandardServletEnvironmentwithPropertySources[servletConfigInitParams,servletContextInitParams,jndiProperties,systemProperties,systemEnvironment]08:48:40[localhost-startStop-1]StandardServletEnvironment-Replacing[servletContextInitParams]PropertySourcewith[servletContextInitParams]08:48:40[localhost-startStop-1]AnnotationConfigWebApplicationContext-RefreshingRootWebApplicationContext:startupdate[WedOct2108:48:40BRST2015];rootofcontexthierarchy08:48:40[localhost-startStop-1]AnnotationConfigWebApplicationContext-Registeringannotatedclasses:[classbr.com.casadocodigo.loja.conf.AppWebConfiguration,classbr.com.casadocodigo.loja.conf.JPAConfiguration]08:48:40[localhost-startStop-1]AnnotationConfigWebApplicationContext-BeanfactoryforRootWebApplicationContext:org.springframework.beans.factory.support.DefaultListableBeanFactory@23e1c6ec:definingbeans[org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,appWebConfiguration,JPAConfiguration];rootoffactoryhierarchy08:48:41[localhost-startStop-1]AutowiredAnnotationBeanPostProcessor-JSR-330'javax.inject.Inject'annotationfoundandsupportedforautowiring08:48:41[localhost-startStop-1]PostProcessorRegistrationDelegate$BeanPostProcessorChecker-Bean'JPAConfiguration'oftype[classbr.com.casadocodigo.loja.conf.JPAConfiguration]isnoteligibleforgettingprocessedbyallBeanPostProcessors(forexample:noteligibleforauto-proxying)08:48:41[localhost-startStop-1]AnnotationConfigWebApplicationContext-UnabletolocateMessageSourcewithname'messageSource':usingdefault[org.springframework.context.support.DelegatingMessageSource@64208072]08:48:41[localhost-startStop-1]AnnotationConfigWebApplicationContext-UnabletolocateApplicationEventMulticasterwithname'applicationEventMulticaster':usingdefault[org.springframework.context.event.SimpleApplicationEventMulticaster@38b10fea]08:48:45[localhost-startStop-1]RequestMappingHandlerMapping-Lookingforrequestmappingsinapplicationcontext:RootWebApplicationContext:startupdate[WedOct2108:48:40BRST2015];rootofcontexthierarchy08:48:45[localhost-startStop-1]RequestMappingHandlerMapping-Mapped"{[/],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String br.com.casadocodigo.loja.controller.HomeController.index()
08:48:45 [localhost-startStop-1] RequestMappingHandlerMapping - Mapped "{[/produtos/form],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String br.com.casadocodigo.loja.controller.ProductsController.form()
08:48:45 [localhost-startStop-1] RequestMappingHandlerMapping - Mapped "{[/produtos/],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String br.com.casadocodigo.loja.controller.ProductsController.save(br.com.casadocodigo.loja.models.Product)
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Looking for URL mappings in application context: Root WebApplicationContext: startup date [Wed Oct 21 08:48:40 BRST 2015]; root of context hierarchy
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'org.springframework.context.annotation.internalRequiredAnnotationProcessor': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'org.springframework.context.annotation.internalCommonAnnotationProcessor': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'org.springframework.context.annotation.internalPersistenceAnnotationProcessor': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'appWebConfiguration': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'JPAConfiguration': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'homeController': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'productsController': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'productDAO': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'resourceHandlerMapping': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'requestMappingHandlerMapping': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'mvcContentNegotiationManager': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'viewControllerHandlerMapping': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'beanNameHandlerMapping': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'mvcResourceUrlProvider': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'httpRequestHandlerAdapter': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'defaultServletHandlerMapping': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'simpleControllerHandlerAdapter': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'requestMappingHandlerAdapter': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'mvcConversionService': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'mvcUriComponentsContributor': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'handlerExceptionResolver': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'mvcPathMatcher': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'mvcUrlPathHelper': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'mvcValidator': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'mvcViewResolver': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'internalResourceViewResolver': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'org.springframework.transaction.config.internalTransactionAdvisor': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'transactionAttributeSource': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'transactionInterceptor': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'dataSource': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'exceptionTranslation': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'transactionManager': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'entityManagerFactory': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'org.springframework.aop.config.internalAutoProxyCreator': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'environment': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'systemProperties': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'systemEnvironment': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'servletContext': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'contextParameters': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'contextAttributes': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'messageSource': no URL paths identified
08:48:45 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'applicationEventMulticaster': no URL paths identified
08:48:45 [localhost-startStop-1] RequestMappingHandlerAdapter - Looking for @ControllerAdvice: Root WebApplicationContext: startup date [Wed Oct 21 08:48:40 BRST 2015]; root of context hierarchy
08:48:46 [localhost-startStop-1] ExceptionHandlerExceptionResolver - Looking for exception mappings: Root WebApplicationContext: startup date [Wed Oct 21 08:48:40 BRST 2015]; root of context hierarchy
08:48:46 [localhost-startStop-1] AnnotationConfigWebApplicationContext - Unable to locate LifecycleProcessor with name 'lifecycleProcessor': using default [org.springframework.context.support.DefaultLifecycleProcessor@70bcac8]
08:48:46 [localhost-startStop-1] ResourceUrlProvider - Looking for resource handler mappings
08:48:46 [localhost-startStop-1] ResourceUrlProvider - No resource handling mappings found
08:48:46 [localhost-startStop-1] ContextLoader - Published root WebApplicationContext as ServletContext attribute with name [org.springframework.web.context.WebApplicationContext.ROOT]
08:48:46 [localhost-startStop-1] ContextLoader - Root WebApplicationContext: initialization completed in 5694 ms
08:48:46 [localhost-startStop-1] DispatcherServlet - Initializing servlet 'dispatcher'
08:48:46 [localhost-startStop-1] StandardServletEnvironment - Adding [servletConfigInitParams] PropertySource with lowest search precedence
08:48:46 [localhost-startStop-1] StandardServletEnvironment - Adding [servletContextInitParams] PropertySource with lowest search precedence
08:48:46 [localhost-startStop-1] StandardServletEnvironment - Adding [jndiProperties] PropertySource with lowest search precedence
08:48:46 [localhost-startStop-1] StandardServletEnvironment - Adding [systemProperties] PropertySource with lowest search precedence
08:48:46 [localhost-startStop-1] StandardServletEnvironment - Adding [systemEnvironment] PropertySource with lowest search precedence
08:48:46 [localhost-startStop-1] StandardServletEnvironment - Initialized StandardServletEnvironment with PropertySources [servletConfigInitParams,servletContextInitParams,jndiProperties,systemProperties,systemEnvironment]
out 21, 2015 8:48:46 AM org.apache.catalina.core.ApplicationContext log
INFORMAÇÕES: Initializing Spring FrameworkServlet 'dispatcher'
08:48:46 [localhost-startStop-1] DispatcherServlet - FrameworkServlet 'dispatcher': initialization started
08:48:46 [localhost-startStop-1] StandardServletEnvironment - Adding [servletConfigInitParams] PropertySource with lowest search precedence
08:48:46 [localhost-startStop-1] StandardServletEnvironment - Adding [servletContextInitParams] PropertySource with lowest search precedence
08:48:46 [localhost-startStop-1] StandardServletEnvironment - Adding [jndiProperties] PropertySource with lowest search precedence
08:48:46 [localhost-startStop-1] StandardServletEnvironment - Adding [systemProperties] PropertySource with lowest search precedence
08:48:46 [localhost-startStop-1] StandardServletEnvironment - Adding [systemEnvironment] PropertySource with lowest search precedence
08:48:46 [localhost-startStop-1] StandardServletEnvironment - Initialized StandardServletEnvironment with PropertySources [servletConfigInitParams,servletContextInitParams,jndiProperties,systemProperties,systemEnvironment]
08:48:46 [localhost-startStop-1] StandardServletEnvironment - Replacing [servletContextInitParams] PropertySource with [servletContextInitParams]
08:48:46 [localhost-startStop-1] StandardServletEnvironment - Replacing [servletConfigInitParams] PropertySource with [servletConfigInitParams]
08:48:46 [localhost-startStop-1] AnnotationConfigWebApplicationContext - Refreshing WebApplicationContext for namespace 'dispatcher-servlet': startup date [Wed Oct 21 08:48:46 BRST 2015]; parent: Root WebApplicationContext
08:48:46 [localhost-startStop-1] AnnotationConfigWebApplicationContext - Bean factory for WebApplicationContext for namespace 'dispatcher-servlet': org.springframework.beans.factory.support.DefaultListableBeanFactory@785814ad: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@23e1c6ec
08:48:46 [localhost-startStop-1] AutowiredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
08:48:46 [localhost-startStop-1] AnnotationConfigWebApplicationContext - Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@7a0438b6]
08:48:46 [localhost-startStop-1] AnnotationConfigWebApplicationContext - Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@4241b627]
08:48:46 [localhost-startStop-1] AnnotationConfigWebApplicationContext - Unable to locate LifecycleProcessor with name 'lifecycleProcessor': using default [org.springframework.context.support.DefaultLifecycleProcessor@3557ec5]
08:48:46 [localhost-startStop-1] DispatcherServlet - Unable to locate MultipartResolver with name 'multipartResolver': no multipart request handling provided
08:48:46 [localhost-startStop-1] DispatcherServlet - Unable to locate LocaleResolver with name 'localeResolver': using default [org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver@13cea2d1]
08:48:46 [localhost-startStop-1] DispatcherServlet - Unable to locate ThemeResolver with name 'themeResolver': using default [org.springframework.web.servlet.theme.FixedThemeResolver@11255868]
08:48:46 [localhost-startStop-1] DispatcherServlet - Unable to locate RequestToViewNameTranslator with name 'viewNameTranslator': using default [org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator@368d22b8]
08:48:46 [localhost-startStop-1] DispatcherServlet - Unable to locate FlashMapManager with name 'flashMapManager': using default [org.springframework.web.servlet.support.SessionFlashMapManager@432020c8]
08:48:46 [localhost-startStop-1] ResourceUrlProvider - Looking for resource handler mappings
08:48:46 [localhost-startStop-1] ResourceUrlProvider - No resource handling mappings found
08:48:46 [localhost-startStop-1] DispatcherServlet - Published WebApplicationContext of servlet 'dispatcher' as ServletContext attribute with name [org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcher]
08:48:46 [localhost-startStop-1] DispatcherServlet - FrameworkServlet 'dispatcher': initialization completed in 46 ms
08:48:46 [localhost-startStop-1] DispatcherServlet - Servlet 'dispatcher' configured successfully
out 21, 2015 8:48:46 AM org.apache.coyote.AbstractProtocol start
INFORMAÇÕES: Starting ProtocolHandler ["http-bio-8080"]
out 21, 2015 8:48:46 AM org.apache.coyote.AbstractProtocol start
INFORMAÇÕES: Starting ProtocolHandler ["ajp-bio-8009"]
out 21, 2015 8:48:46 AM org.apache.catalina.startup.Catalina start
INFORMAÇÕES: Server startup in 11543 ms
08:49:06 [http-bio-8080-exec-3] DispatcherServlet - DispatcherServlet with name 'dispatcher' processing GET request for [/lojacasadocodigo/produtos/form]
08:49:06 [http-bio-8080-exec-3] RequestMappingHandlerMapping - Looking up handler method for path /produtos/form
08:49:06 [http-bio-8080-exec-3] RequestMappingHandlerMapping - Returning handler method [public java.lang.String br.com.casadocodigo.loja.controller.ProductsController.form()]
08:49:06 [http-bio-8080-exec-3] DispatcherServlet - Last-Modified value for [/lojacasadocodigo/produtos/form] is: -1
08:49:06 [http-bio-8080-exec-3] DispatcherServlet - Rendering view [org.springframework.web.servlet.view.JstlView: name 'products/form'; URL [/WEB-INF/views/products/form.jsp]] in DispatcherServlet with name 'dispatcher'
08:49:06 [http-bio-8080-exec-3] JstlView - Forwarding to resource [/WEB-INF/views/products/form.jsp] in InternalResourceView 'products/form'
08:49:06 [http-bio-8080-exec-3] DispatcherServlet - Successfully completed request

this was the configuration used;

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN" "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

    <!-- Appenders -->
    <appender name="console" class="org.apache.log4j.ConsoleAppender">
        <param name="Target" value="System.out" />
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{HH:mm:ss} [%t] %c{1} - %m%n" />
        </layout>
    </appender>

    <logger name="org.springframework.samples">
        <level value="debug" />
    </logger>

    <logger name="org.springframework.core">
        <level value="info" />
    </logger>

    <logger name="org.springframework.beans">
        <level value="info" />
    </logger>

    <logger name="org.springframework.context">
        <level value="info" />
    </logger>

    <logger name="org.springframework.http">
        <level value="debug" />
    </logger>

    <logger name="org.springframework.web">
        <level value="debug" />
    </logger>

    <root>
        <priority value="warn" />
        <appender-ref ref="console" />
    </root>

</log4j:configuration>

What I'm needing is trying to save things in the bank and I can not.

Could you help me see if there is anything that would indicate problems with entering the record in the bank?

    
asked by anonymous 21.10.2015 / 03:19

2 answers

5

The first thing you should do is to add a log setting to display errors in the console or in a log file.

I saw in% w / o% of your project that is using Log4j, so that means it would be interesting to put a pom.xml in the log4j.xml folder.

Without the error / exception one could just guess at the cause of the problem with little chance of getting it right.

However, quickly looking at some classes I noticed that you are returning src/main/resources in the listing, but there is no view called products/ok :

@Controller
@Transactional
public class ProductsController {

    @Autowired
    private ProductDAO productDAO;

    @RequestMapping("/produtos/")
    public String save(Product product){
        productDAO.save(product);
        return "products/ok";
    }

    @RequestMapping("/produtos/form")
    public String form(){
        return "products/form";
    }


}

One tip: on a truth system, do not declare transactions on controllers, let alone on the whole class.

It is not the controllers responsibility to demarcate transactional blocks. In addition to that you end up putting transactions where you do not need, as in methods of consultation or that do not even access the bank.

    
21.10.2015 / 06:36
-2

Hi, the 404 is because the page ok does not exist. Just create ... Regarding @Transactional annotation on Controller, I do not agree. The controller invokes multiple business points in your application, it almost functions as a service, so it makes a lot of sense to mark the transaction there. Who controls the scope of a transaction is who uses the business classes ...

    
21.10.2015 / 23:59