当我向ContextLoaderListener
添加web.xml
时,会收到资源未找到的消息(404)。当我从web.xml
删除侦听器类,然后我的index.php
正在运行但添加
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
web.xml
中添加这两行并准备代码时,它就是这个错误:< / LI>
java.lang.IllegalStateException:找不到WebApplicationContext:没有注册ContextLoaderListener?
我很努力,我是Spring框架的新手。你能告诉我听众或其他什么需要设置吗?
控制台出错:
*
Jan 27, 2016 12:47:24 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanDefinitionStoreException: Parser configuration exception parsing XML from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is javax.xml.parsers.ParserConfigurationException: Unable to validate using XSD: Your JAXP provider [org.apache.crimson.jaxp.DocumentBuilderFactoryImpl@1cefe08] does not support XML Schema. Are you running on Java 1.4 or below with Apache Crimson? Upgrade to Apache Xerces (or Java 1.5) for full XSD support.
*
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>FutureKid</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>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<servlet>
<description></description>
<display-name>InputFormServlet</display-name>
<servlet-name>InputFormServlet</servlet-name>
<servlet-class>com.webapp.InputFormServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>InputFormServlet</servlet-name>
<url-pattern>/input-form</url-pattern>
</servlet-mapping>
<servlet>
<description></description>
<display-name>CustomerServlet</display-name>
<servlet-name>CustomerServlet</servlet-name>
<servlet-class>com.webapp.CustomerServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CustomerServlet</servlet-name>
<url-pattern>/get-customer</url-pattern>
</servlet-mapping>
</web-app>
答案 0 :(得分:0)
只是添加ContextLoaderListener
并不是唯一的,您还需要配置ContextLoaderListener
加载的bean。 Tyicaly你为ContextLoaderListener
(通过context-param contextConfigLocation
)配置spring xml文件的名称,然后在这个文件中添加一些spring配置。
你也应该阅读"ContextLoaderListener or not?" question and its answers,它会让你对两个春天的背景有一些了解。它还包含web.xml
答案 1 :(得分:0)
首先将以下内容添加到您的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
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/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing
infrastructure -->
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving
up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<beans:bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/" />
<beans:property name="suffix" value=".jsp" />
<beans:property name="order" value="1" />
</beans:bean>
</beans:beans>
接下来在WEB-INF / spring文件夹中创建一个spring.xml,并根据需要进行更改。
示例spring.xml
{{1}}