以下是我配置的配置文件
WEB-INF / classes / applicationContext.xml但它正在搜索 WEB-INF / applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="starter_anil" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Anil-Spring</display-name>
<!-- Servlets -->
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/classes/applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<!-- Listeners -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
我正在接受例外
EVERE: Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml]
这是我的applicationContext
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<import resource="config/controllers.xml" />
<!-- <import resource="conf/spring/services.xml" />
<import resource="conf/spring/persistence.xml" />
<import resource="conf/spring/daos.xml" />
<import resource="conf/spring//interceptors.xml" /> -->
</beans>
解决方法是
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="starter_anil" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Anil-Spring</display-name>
<!-- Servlets -->
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml</param-value>
</context-param>
<!-- Listeners -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
警告:找不到带URI的HTTP请求的映射 DispatcherServlet中的[/AnilsSpring/WEB-INF/jsp/hello.jsp]名称 'MVC-调度' 请指导我一次
答案 0 :(得分:1)
为什么你的applicationContext
在课堂上?将其移至WEB-INF目录,如评论中所述。这应该解决问题。
/ classes目录用于编译的类,但不用于配置文件。
答案 1 :(得分:0)
尝试在/
/WEB-INF/classes/applicationContext.xml
如果它仍然不起作用,请尝试在web.xml
(在servlet声明之前)中添加它
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/classes/applicationContext.xml
</param-value>
</context-param>
答案 2 :(得分:0)
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="starter_anil" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Anil-Spring</display-name>
<!-- Servlets -->
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml</param-value>
</context-param>
<!-- Listeners -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
这使得tomcat上的异常开始少,但我有点困惑
答案 3 :(得分:0)
如果您绝对必须拥有它,请尝试:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="starter_anil" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Anil-Spring</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<the-rest-of-your-stuff />
</web-app>
/
之前可能需要applicationContext.xml
,但我不这么认为。
答案 4 :(得分:0)
可能是你需要取消部署。并部署它。它会工作。 。 它适用于我的例外 IOException从ServletContext资源解析XML文档[/ WEB-INF / classes / spring application config.xml];
答案 5 :(得分:-1)
WEB-INF / classes / applicationContext.xml对于这个要求,你必须把applicationContext.xml放在类路径中,即
如果您使用的是maven,请将其放在src / main / resources文件夹中,否则放入src文件夹。
然后你会在WEB-INF / classes
中找到它