spring,hibernate,MVC,如何检测映射有什么问题

时间:2016-04-15 20:18:07

标签: hibernate spring-mvc tomcat netbeans-8

我使用Netbeans 8.1从和下载解决方案和托盘2教程 P1。 Spring Hibernate Integration Example Tutorial (Spring 4 + Hibernate 3 and Hibernate 4) P2。 Spring MVC Hibernate MySQL Integration CRUD Example Tutorial 原始项目是与eclipse。我用过Netbeans。

P1工作正常。

当我跑P2时,我得到了:

HTTP状态404 - 和 没有找到带URI的HTTP请求的映射,如下所示。

System.exit

以下是部署的内容:

15-Apr-2016 14:59:46.813 INFO [http-apr-8080-exec-24] org.apache.catalina.startup.HostConfig.deployDescriptor Deploying configuration descriptor C:\IT\apache-tomcat-8.0.32\conf\Catalina\localhost\SpringMVCHibernate.xml
INFO : org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization started
INFO : org.springframework.web.context.support.XmlWebApplicationContext - Refreshing Root WebApplicationContext: startup date [Fri Apr 15 14:59:57 CDT 2016]; root of context hierarchy
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/spring/root-context.xml]
INFO : org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization completed in 383 ms
INFO : org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'appServlet': initialization started
INFO : org.springframework.web.context.support.XmlWebApplicationContext - Refreshing WebApplicationContext for namespace 'appServlet-servlet': startup date [Fri Apr 15 14:59:58 CDT 2016]; parent: Root WebApplicationContext
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml]
INFO : org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/persons],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.journaldev.spring.PersonController.listPersons(org.springframework.ui.Model)
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/person/add],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.journaldev.spring.PersonController.addPerson(com.journaldev.spring.model.Person)
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/remove/{id}],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.journaldev.spring.PersonController.removePerson(int)
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/edit/{id}],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.journaldev.spring.PersonController.editPerson(int,org.springframework.ui.Model)
INFO : org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/resources/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0'
INFO : org.hibernate.annotations.common.Version - HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
INFO : org.hibernate.Version - HHH000412: Hibernate Core {4.3.5.Final}
INFO : org.hibernate.cfg.Environment - HHH000206: hibernate.properties not found
INFO : org.hibernate.cfg.Environment - HHH000021: Bytecode provider name : javassist
INFO : org.hibernate.dialect.Dialect - HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
INFO : org.hibernate.engine.jdbc.internal.LobCreatorBuilder - HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
INFO : org.hibernate.engine.transaction.internal.TransactionFactoryInitiator - HHH000399: Using default transaction strategy (direct JDBC transactions)
INFO : org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory - HHH000397: Using ASTQueryTranslatorFactory
INFO : org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'appServlet': initialization completed in 8082 ms
15-Apr-2016 15:00:06.429 INFO [http-apr-8080-exec-24] org.apache.catalina.startup.HostConfig.deployDescriptor Deployment of configuration descriptor C:\IT\apache-tomcat-8.0.32\conf\Catalina\localhost\SpringMVCHibernate.xml has finished in 19,616 ms
15-Apr-2016 15:00:06.433 INFO [http-apr-8080-exec-22] org.apache.catalina.util.LifecycleBase.start The start() method was called on component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/SpringMVCHibernate]] after start() had already been called. The second call will be ignored.
WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/SpringMVCHibernate/] in DispatcherServlet with name 'appServlet'

我的问题是,只要我保留原始文件,如何检测映射有什么问题?

感谢您的帮助。

M Toma

更新

personControler.java

Volume in drive C is OS
 Volume Serial Number is ...

 ... apache-tomcat-8.0.32\webapps\SpringMVCHibernate

04/15/2016  02:59 PM    <DIR>          .
04/15/2016  02:59 PM    <DIR>          ..
04/15/2016  02:59 PM    <DIR>          META-INF
04/15/2016  02:59 PM    <DIR>          WEB-INF
               0 File(s)              0 bytes

 ... apache-tomcat-8.0.32\webapps\SpringMVCHibernate\META-INF

04/15/2016  02:59 PM    <DIR>          .
04/15/2016  02:59 PM    <DIR>          ..
04/15/2016  07:45 AM                77 context.xml
04/15/2016  07:55 AM               125 MANIFEST.MF
04/15/2016  02:59 PM    <DIR>          maven
04/15/2016  07:55 AM                 0 war-tracker
               3 File(s)            202 bytes

 ... apache-tomcat-8.0.32\webapps\SpringMVCHibernate\META-INF\maven

04/15/2016  02:59 PM    <DIR>          .
04/15/2016  02:59 PM    <DIR>          ..
04/15/2016  02:59 PM    <DIR>          com.journaldev.spring
               0 File(s)              0 bytes

 ... apache-tomcat-8.0.32\webapps\SpringMVCHibernate\META-INF\maven\com.journaldev.spring

04/15/2016  02:59 PM    <DIR>          .
04/15/2016  02:59 PM    <DIR>          ..
04/15/2016  02:59 PM    <DIR>          SpringMVCHibernate
               0 File(s)              0 bytes

 ... apache-tomcat-8.0.32\webapps\SpringMVCHibernate\META-INF\maven\com.journaldev.spring\SpringMVCHibernate

04/15/2016  02:59 PM    <DIR>          .
04/15/2016  02:59 PM    <DIR>          ..
04/15/2016  07:55 AM               144 pom.properties
04/15/2016  07:55 AM             6,127 pom.xml
               2 File(s)          6,271 bytes

 ... apache-tomcat-8.0.32\webapps\SpringMVCHibernate\WEB-INF

04/15/2016  02:59 PM    <DIR>          .
04/15/2016  02:59 PM    <DIR>          ..
04/15/2016  02:59 PM    <DIR>          classes
04/15/2016  02:59 PM    <DIR>          lib
04/15/2016  02:59 PM    <DIR>          spring
04/15/2016  02:59 PM    <DIR>          views
07/19/2014  08:58 PM             1,206 web.xml
               1 File(s)          1,206 bytes

 ... apache-tomcat-8.0.32\webapps\SpringMVCHibernate\WEB-INF\classes

04/15/2016  02:59 PM    <DIR>          .
04/15/2016  02:59 PM    <DIR>          ..
04/15/2016  02:59 PM    <DIR>          com
04/15/2016  07:55 AM             1,111 log4j.xml
               1 File(s)          1,111 bytes

 ... apache-tomcat-8.0.32\webapps\SpringMVCHibernate\WEB-INF\classes\com

04/15/2016  02:59 PM    <DIR>          .
04/15/2016  02:59 PM    <DIR>          ..
04/15/2016  02:59 PM    <DIR>          journaldev
               0 File(s)              0 bytes

 ... apache-tomcat-8.0.32\webapps\SpringMVCHibernate\WEB-INF\classes\com\journaldev

04/15/2016  02:59 PM    <DIR>          .
04/15/2016  02:59 PM    <DIR>          ..
04/15/2016  02:59 PM    <DIR>          spring
               0 File(s)              0 bytes

 ... apache-tomcat-8.0.32\webapps\SpringMVCHibernate\WEB-INF\classes\com\journaldev\spring

04/15/2016  02:59 PM    <DIR>          .
04/15/2016  02:59 PM    <DIR>          ..
04/15/2016  02:59 PM    <DIR>          dao
04/15/2016  02:59 PM    <DIR>          model
04/15/2016  07:55 AM             2,576 PersonController.class
04/15/2016  02:59 PM    <DIR>          service
               1 File(s)          2,576 bytes

 ... apache-tomcat-8.0.32\webapps\SpringMVCHibernate\WEB-INF\classes\com\journaldev\spring\dao

04/15/2016  02:59 PM    <DIR>          .
04/15/2016  02:59 PM    <DIR>          ..
04/15/2016  07:55 AM               428 PersonDAO.class
04/15/2016  07:55 AM             3,306 PersonDAOImpl.class
               2 File(s)          3,734 bytes

 ... apache-tomcat-8.0.32\webapps\SpringMVCHibernate\WEB-INF\classes\com\journaldev\spring\model

04/15/2016  02:59 PM    <DIR>          .
04/15/2016  02:59 PM    <DIR>          ..
04/15/2016  07:55 AM             1,534 Person.class
               1 File(s)          1,534 bytes

 ... apache-tomcat-8.0.32\webapps\SpringMVCHibernate\WEB-INF\classes\com\journaldev\spring\service

04/15/2016  02:59 PM    <DIR>          .
04/15/2016  02:59 PM    <DIR>          ..
04/15/2016  07:55 AM               440 PersonService.class
04/15/2016  07:55 AM             1,587 PersonServiceImpl.class
               2 File(s)          2,027 bytes

 ... apache-tomcat-8.0.32\webapps\SpringMVCHibernate\WEB-INF\lib

04/15/2016  02:59 PM    <DIR>          .
04/15/2016  02:59 PM    <DIR>          ..
02/28/2015  04:11 PM           445,288 antlr-2.7.7.jar
03/15/2015  11:53 AM             4,467 aopalliance-1.0.jar
04/06/2016  12:33 PM           119,683 aspectjrt-1.7.4.jar
03/15/2015  11:53 AM           160,519 commons-dbcp-1.4.jar
03/15/2015  11:53 AM            96,221 commons-pool-1.5.4.jar
02/28/2015  04:11 PM           313,898 dom4j-1.6.1.jar
03/15/2015  12:10 PM            75,311 hibernate-commons-annotations-4.0.4.Final.jar
03/15/2015  12:10 PM         5,230,007 hibernate-core-4.3.5.Final.jar
04/06/2016  12:33 PM           645,914 hibernate-entitymanager-4.3.5.Final.jar
02/28/2015  04:08 PM           113,371 hibernate-jpa-2.1-api-1.0.0.Final.jar
02/28/2015  04:11 PM            76,551 jandex-1.1.0.Final.jar
02/28/2015  04:11 PM           714,194 javassist-3.18.1-GA.jar
02/27/2015  11:25 AM             2,497 javax.inject-1.jar
02/28/2015  04:08 PM            57,183 jboss-logging-3.1.3.GA.jar
02/28/2015  04:08 PM            11,558 jboss-logging-annotations-1.2.0.Beta1.jar
02/28/2015  04:08 PM            27,717 jboss-transaction-api_1.2_spec-1.0.0.Final.jar
03/14/2015  08:32 AM            16,517 jcl-over-slf4j-1.7.5.jar
02/28/2015  04:11 PM           414,240 jstl-1.2.jar
03/16/2016  02:50 PM           391,834 log4j-1.2.15.jar
03/15/2015  11:53 AM           724,213 mysql-connector-java-5.1.9.jar
03/14/2015  08:32 AM            26,084 slf4j-api-1.7.5.jar
04/06/2016  09:46 AM             8,869 slf4j-log4j12-1.7.5.jar
03/15/2015  11:53 AM           352,700 spring-aop-4.0.3.RELEASE.jar
03/15/2015  11:53 AM           669,978 spring-beans-4.0.3.RELEASE.jar
03/15/2015  11:53 AM           974,938 spring-context-4.0.3.RELEASE.jar
03/15/2015  11:53 AM           973,502 spring-core-4.0.3.RELEASE.jar
03/15/2015  11:53 AM           204,745 spring-expression-4.0.3.RELEASE.jar
03/15/2015  11:53 AM           424,466 spring-jdbc-4.0.3.RELEASE.jar
03/15/2015  11:53 AM           366,892 spring-orm-4.0.3.RELEASE.jar
03/15/2015  11:53 AM           248,201 spring-tx-4.0.3.RELEASE.jar
04/09/2015  11:22 AM           667,960 spring-web-4.0.3.RELEASE.jar
04/09/2015  11:22 AM           662,385 spring-webmvc-4.0.3.RELEASE.jar
02/28/2015  04:12 PM           109,318 xml-apis-1.0.b2.jar
              33 File(s)     15,331,221 bytes

 ... apache-tomcat-8.0.32\webapps\SpringMVCHibernate\WEB-INF\spring

04/15/2016  02:59 PM    <DIR>          .
04/15/2016  02:59 PM    <DIR>          ..
04/15/2016  02:59 PM    <DIR>          appServlet
07/19/2014  08:58 PM               380 root-context.xml
               1 File(s)            380 bytes

 ... apache-tomcat-8.0.32\webapps\SpringMVCHibernate\WEB-INF\spring\appServlet

04/15/2016  02:59 PM    <DIR>          .
04/15/2016  02:59 PM    <DIR>          ..
07/19/2014  08:58 PM             3,242 servlet-context.xml
               1 File(s)          3,242 bytes

 ... apache-tomcat-8.0.32\webapps\SpringMVCHibernate\WEB-INF\views

04/15/2016  02:59 PM    <DIR>          .
04/15/2016  02:59 PM    <DIR>          ..
07/19/2014  08:58 PM             2,484 person.jsp
               1 File(s)          2,484 bytes

     Total Files Listed:
              49 File(s)     15,355,988 bytes

当我在netbeas中运行应用程序时,它是在服务器上部署和启动web的人。我不是那个写url地址的人。

Netbeans让我通过右键单击菜单(server - tomcat - SpringMVCHibernate)来启动,停止,在浏览器中打开。

我尝试了其他一些网址,但没有成功。

所有来源都可以在P2的地址上看到。

更新

我更改了log4j.xml级别,以下是我在浏览器中打开的内容:

package com.journaldev.spring;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.journaldev.spring.model.Person;
import com.journaldev.spring.service.PersonService;

@Controller
public class PersonController {

    private PersonService personService;

    @Autowired(required=true)
    @Qualifier(value="personService")
    public void setPersonService(PersonService ps){
        this.personService = ps;
    }

    @RequestMapping(value = "/persons", method = RequestMethod.GET)
    public String listPersons(Model model) {
        model.addAttribute("person", new Person());
        model.addAttribute("listPersons", this.personService.listPersons());
        return "person";
    }

    //For add and update person both
    @RequestMapping(value= "/person/add", method = RequestMethod.POST)
    public String addPerson(@ModelAttribute("person") Person p){

        if(p.getId() == 0){
            //new person, add it
            this.personService.addPerson(p);
        }else{
            //existing person, call update
            this.personService.updatePerson(p);
        }

        return "redirect:/persons";

    }

    @RequestMapping("/remove/{id}")
    public String removePerson(@PathVariable("id") int id){

        this.personService.removePerson(id);
        return "redirect:/persons";
    }

    @RequestMapping("/edit/{id}")
    public String editPerson(@PathVariable("id") int id, Model model){
        model.addAttribute("person", this.personService.getPersonById(id));
        model.addAttribute("listPersons", this.personService.listPersons());
        return "person";
    }

}

我认为一些相关问题是:
TRACE: org.springframework.web.servlet.DispatcherServlet - Bound request context to thread: uri: /SpringMVCHibernate/ method: GET QueryString: null Parameters: Headers: Name: host Value: localhost:8080 Name: user-agent Value: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0 Name: accept Value: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Name: accept-language Value: en-US,en;q=0.5 Name: accept-encoding Value: gzip, deflate Name: dnt Value: 1 Name: connection Value: keep-alive DEBUG: org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'appServlet' processing GET request for [/SpringMVCHibernate/] TRACE: org.springframework.web.servlet.DispatcherServlet - Testing handler map [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping@43edc0b9] in DispatcherServlet with name 'appServlet' DEBUG: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Looking up handler method for path / DEBUG: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Did not find handler method for [/] TRACE: org.springframework.web.servlet.DispatcherServlet - Testing handler map [org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping@170563eb] in DispatcherServlet with name 'appServlet' TRACE: org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping - No handler mapping found for [/] TRACE: org.springframework.web.servlet.DispatcherServlet - Testing handler map [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping@5256ecaa] in DispatcherServlet with name 'appServlet' TRACE: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - No handler mapping found for [/] WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/SpringMVCHibernate/] in DispatcherServlet with name 'appServlet' TRACE: org.springframework.web.servlet.DispatcherServlet - Cleared thread-bound request context: uri: /SpringMVCHibernate/ method: GET QueryString: null Parameters: Headers: Name: host Value: localhost:8080 Name: user-agent Value: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0 Name: accept Value: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Name: accept-language Value: en-US,en;q=0.5 Name: accept-encoding Value: gzip, deflate Name: dnt Value: 1 Name: connection Value: keep-alive DEBUG: org.springframework.web.servlet.DispatcherServlet - Successfully completed request TRACE: org.springframework.web.context.support.XmlWebApplicationContext - Publishing event in WebApplicationContext for namespace 'appServlet-servlet': ServletRequestHandledEvent: url=[/SpringMVCHibernate/]; client=[127.0.0.1]; method=[GET]; servlet=[appServlet]; session=[null]; user=[null]; time=[2ms]; status=[OK] TRACE: org.springframework.web.context.support.XmlWebApplicationContext - Publishing event in Root WebApplicationContext: ServletRequestHandledEvent: url=[/SpringMVCHibernate/]; client=[127.0.0.1]; method=[GET]; servlet=[appServlet]; session=[null]; user=[null]; time=[2ms]; status=[OK] servlet-context.xmlroot-context.xml的用途是什么? 为什么DispatcherServlet会创建另一个应用程序上下文? 上下文初始化失败或加载属性
根上下文和调度程序servlet上下文到底是如何进入Spring MVC Web应用程序的?

尝试在Eclipse上运行示例并获得相同的结果:

web.xml

仍然不知道如何修复以及如何检测应用程序的错误。 谢谢你的帮助。

2 个答案:

答案 0 :(得分:0)

您的项目中有一个Controller,它会处理一组网址。 它在您项目的日志级别INFO上提及。

INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/persons],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.journaldev.spring.PersonController.listPersons(org.springframework.ui.Model)
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/person/add],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.journaldev.spring.PersonController.addPerson(com.journaldev.spring.model.Person)
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/remove/{id}],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.journaldev.spring.PersonController.removePerson(int)
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/edit/{id}],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.journaldev.spring.PersonController.editPerson(int,org.springframework.ui.Model)
INFO : org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/resources/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0'

是:

/persons 
/person/add
/remove/{id}
/edit/{id}

您的警告是因为您使用以下表单致电Url

http://localhost:xxxx/SpringMVCHibernate/

未映射到您的servlet上。

答案 1 :(得分:0)

我再次托起Netbeans的例子,让它发挥作用。我希望在网址上看到一个页面,这是错误的:http://localhost:8080/SpringMVCHibernate如果我将网址更改为:http://localhost:8080/SpringMVCHibernate/persons我收到错误:

HTTP Status 500 – Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.GenericJDBCException: Could not open connection
…
org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class ‘com.mysql.jdbc.Driver’

我添加了mysql-connector,我看到了正确的页面; 谢谢你的评论 M. Toma