Spring MVC servlet没有初始化

时间:2015-03-27 08:17:26

标签: spring-mvc tomcat7

我在我的Kepler Eclipse中配置了tomcat 7。截至目前,我已向此服务器添加了三个应用程序。在三个服务器中,两个应用程序的servlet正在初始化,而剩下的一个应用程序在初始化时面临问题,并且在浏览器上遇到此应用程序的请求时,我得到404资源未找到异常。

以下是正在服务器中添加的应用程序的屏幕截图 -

Applications added in the server

如上所示,MVC_CRUD_SPRING应用程序未被服务器初始化。

以下是服务器启动时的控制台日志 -

Mar 27, 2015 1:00:13 PM org.apache.catalina.core.AprLifecycleListener   init
INFO: The APR based Apache Tomcat Native library which al lows optimal   performance in production environments was not found on the  java.library.path: C:\Program Files\Java\jre7\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Java\jdk1.7.0_60\bin;C:\cygwin64\bin;C:\cygwin64\usr\sbin;C:\Program Files\apache-maven-3.2.5\bin;C:\Program Files\EmEditor;.
Mar 27, 2015 1:00:13 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context}  Setting   property 'source' to 'org.eclipse.jst.jee.server:HelloSpringMVCForm' did not find a matching property.
Mar 27, 2015 1:00:13 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting  property 'source' to 'org.eclipse.jst.jee.server:MVC_CRUD_SPRING' did not find a matching property.
Mar 27, 2015 1:00:13 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting  property 'source' to 'org.eclipse.jst.jee.server:HelloWeb' did not find a matching property.
Mar 27, 2015 1:00:13 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Mar 27, 2015 1:00:13 PM org.apache.coyote.ajp.AjpProtocol init
INFO: Initializing Coyote AJP/1.3 on ajp-8009
Mar 27, 2015 1:00:13 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1015 ms
Mar 27, 2015 1:00:13 PM org.apache.catalina.core.StandardService   startInternal
INFO: Starting service Catalina
Mar 27, 2015 1:00:13 PM org.apache.catalina.core.StandardEngine   startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.4
Mar 27, 2015 1:00:17 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://www.springframework.org/tags/form is  already defined
Mar 27, 2015 1:00:17 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://www.springframework.org/tags is already  defined
Mar 27, 2015 1:00:18 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'HelloWebMVCServlet'
Mar 27, 2015 1:00:18 PM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'HelloWebMVCServlet': initialization started
Mar 27, 2015 1:00:18 PM   org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'HelloWebMVCServlet- servlet': startup date [Fri Mar 27 13:00:18 IST 2015]; root of context hierarchy
Mar 27, 2015 1:00:18 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/HelloWebMVCServlet-servlet.xml]
Mar 27, 2015 1:00:18 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@5ccaed61: defining beans [contactController,helloController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.web.servlet.view.InternalResourceViewResolver#0]; root of factory hierarchy
Mar 27, 2015 1:00:19 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Root mapping to handler [com.tutorialspoint.ContactController@27c73122]
Mar 27, 2015 1:00:19 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/contacts] onto handler [com.tutorialspoint.ContactController@27c73122]
Mar 27, 2015 1:00:19 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/contacts.*] onto handler [com.tutorialspoint.ContactController@27c73122]
Mar 27, 2015 1:00:19 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/contacts/] onto handler [com.tutorialspoint.ContactController@27c73122]
Mar 27, 2015 1:00:19 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/addContact] onto handler [com.tutorialspoint.ContactController@27c73122]
Mar 27, 2015 1:00:19 PM  org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/addContact.*] onto handler [com.tutorialspoint.ContactController@27c73122]
Mar 27, 2015 1:00:19 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/addContact/] onto handler [com.tutorialspoint.ContactController@27c73122]
Mar 27, 2015 1:00:19 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/hello] onto handler [com.tutorialspoint.HelloController@a37f72b]
Mar 27, 2015 1:00:19 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/hello.*] onto handler [com.tutorialspoint.HelloController@a37f72b]
Mar 27, 2015 1:00:19 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/hello/] onto handler [com.tutorialspoint.HelloController@a37f72b]
Mar 27, 2015 1:00:19 PM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'HelloWebMVCServlet': initialization completed in 936 ms
Mar 27, 2015 1:00:19 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'HelloWeb'
Mar 27, 2015 1:00:19 PM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'HelloWeb': initialization started
Mar 27, 2015 1:00:19 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'HelloWeb-servlet': startup date [Fri Mar 27 13:00:19 IST 2015]; root of context hierarchy
Mar 27, 2015 1:00:19 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/HelloWeb-servlet.xml]
Mar 27, 2015 1:00:20 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in  org.springframework.beans.factory.support.DefaultListableBeanFactory@1d2bd198: defining beans [helloController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.web.servlet.view.InternalResourceViewResolver#0]; root of factory hierarchy
Mar 27, 2015 1:00:20 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/hello] onto handler [com.tutorialspoint.HelloController@7b22bfc2]
Mar 27, 2015 1:00:20 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/hello.*] onto handler [com.tutorialspoint.HelloController@7b22bfc2]
Mar 27, 2015 1:00:20 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/hello/] onto handler [com.tutorialspoint.HelloController@7b22bfc2]
Mar 27, 2015 1:00:20 PM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'HelloWeb': initialization completed in 801 ms
Mar 27, 2015 1:00:20 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Mar 27, 2015 1:00:20 PM org.apache.coyote.ajp.AjpProtocol start
INFO: Starting Coyote AJP/1.3 on ajp-8009
Mar 27, 2015 1:00:20 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 6900 ms

如果检查上面的日志,则不会看到位于MVC_CRUD_SPRING应用程序中的任何Employee-servlet初始化日志。

检查server.xml上下文条目 -

<Context docBase="HelloSpringMVCForm" path="/HelloSpringMVCForm" reloadable="true" source="org.eclipse.jst.jee.server:HelloSpringMVCForm"/>
<Context docBase="MVC_CRUD_SPRING" path="/MVC_CRUD_SPRING" reloadable="true" source="org.eclipse.jst.jee.server:MVC_CRUD_SPRING"/>
<Context docBase="HelloWeb" path="/HelloWeb" reloadable="true" source="org.eclipse.jst.jee.server:HelloWeb"/>

MVC_CRUD_SPRING的web.xml如下:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>MVC_CRUD_SPRING</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>

<servlet>
<servlet-name>employee</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>employee</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
</web-app>

employee-servlet.xml如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans     
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<context:property-placeholder location="classpath:database.properties"/
<context:component-scan base-package="com.cybage.projects"> </context:component-scan>
<tx:annotation-driven transaction-manager="hibernateTransactionManager"></tx:annotation-driven>

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="jspViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>
<property name="prefix" value="/WEB-INF/"></property>
<property name="suffix" value=".jsp"></property>
<property name="order" value="1"></property>
</bean>  

<bean class="org.springframework.jdbc.datasource.DriverManagerDataSource" id="dataSource">
<property name="driverClassName" value="${database.driver}"></property>
<property name="url" value="${database.url}"></property>
<property name="username" value="${database.url}"></property>
<property name="password" value="${database.password}"></property>
</bean>

<bean class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" id="sessionFactory">
<property name="dataSource" ref="dataSource"></property>
<property name="annotatedClasses">
<list>
<value>com.cybage.projects.model.Employee</value>
</list> 
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
</props>
</property>
</bean>

<bean class="org.springframework.orm.hibernate3.HibernateTransactionManager" id="hibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean> 

对此的任何帮助都将受到高度赞赏。

0 个答案:

没有答案