java - ContextLoaderListener 触发器 applicationContext.xml 文件未找到
问题描述
我没有 applicationContext.xml。我不需要它。
这是我的web.xml
文件:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigurationLocation</param-name>
<param-value>/WEB-INF/config/security-config.xml</param-value>
</context-param>
...
<servlet>
<servlet-name>fitTrackerServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/servlet-config.xml</param-value>
</init-param>
</servlet>
我在security-config.xml
那里有那个文件,它看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.2.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-3.2.xsd">
<http auto-config="true">
<intercept-url pattern="/**" access="ROLE_USER"/>
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="ajde" password="ajde" authorities="ROLE_USER" />
</user-service>
</authentication-provider>
</authentication-manager>
</beans:beans>
而且我仍然得到错误,就像我没有一样applicationContext.xml
。
SEVERE: 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]
这怎么可能?!?
我看不出我做错了什么。
很明显,这是一条路径。但是将 servlet 配置 servlet-config.xml 放在相同的目录下工作。
我将我的复制/粘贴security-config.xml
到 的根目录WEB-INF
,然后将其重命名为applicationContext.xml
...它可以工作!!!!!!
所以,我做错了什么?!?!?我看不到...
解决方案
侦听器检查 contextConfigLocation 参数。如果参数不存在,则监听器使用 /WEB-INF/applicationContext.xml 作为默认值。当参数确实存在时,侦听器使用预定义的分隔符(逗号、分号和空格)分隔字符串,并将这些值用作将搜索应用程序上下文的位置。也支持 Ant 样式的路径模式。示例是 /WEB-INF/*Context.xml 用于名称以“Context.xml”结尾的所有文件,位于“WEB-INF”目录中,/WEB-INF/**/*Context.xml 用于所有此类文件位于“WEB-INF”的任何子目录中。
您可以避免 applicationContext.xml,但它看起来像解决方法https://www.nurkiewicz.com/2011/01/spring-framework-without-xml-at-all.html
推荐阅读
- avaloniaui - 为什么在面板之间移动控件会导致延迟渲染出现异常?
- python - Kivy TextInput 位于 Android 键盘上方,但屏幕其余部分保持原位
- android - Android OpenGL ES,形状未显示在设备上,但在模拟器上工作正常?
- php - PayPal PHP SDK - 如何通过 PayPal 传递自定义变量?
- windows - 如何使用 Powershell 检查操作系统架构(32 位或 64 位)?
- moodle - 由于没有此类活动,因此无法在 Moodle 中创建考勤
- java - 使用tomcat9 + Memcache时,会话之间的HttpSession对象变为空
- spring - DatastoreException:给定的键没有字符串名称值,但尝试转换为字符串
- sql - 当 dblink 失败时,使用 UNION 的视图无法返回查询的第一部分的结果
- python - 用于 systemd 服务的 Python ImportError