Java Spring MVC:添加securityConfig.xml和dispatcherContext.xml

Java Spring MVC:添加securityConfig.xml和dispatcherContext.xml,java,spring,spring-security,web.xml,Java,Spring,Spring Security,Web.xml,我在web.xml中遇到了这段代码,但我不知道如何将securityConfig.xml与dispatcherContext.xml一起添加到类路径中 <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:dispatcherContext.xml</param-value> </context-par

我在web.xml中遇到了这段代码,但我不知道如何将
securityConfig.xml
dispatcherContext.xml一起添加到类路径中

<context-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>classpath:dispatcherContext.xml</param-value>
</context-param>
我得到下面的例外

ContextLoader - Context initialization failed
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath:securityConfig.xml]
Offending resource: class path resource [dispatcherContext.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [securityConfig.xml]; nested exception is java.io.FileNotFoundException: class path resource [securityConfig.xml] cannot be opened because it does not exist
    at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
    at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
    at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:76)

只需在根上下文定义(在您的情况下为dispatcherContext.xml)文件中使用import:


但您可以通过在文件名之间放置空格B来提供多个选项:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>dispatcherContext.xml securityConfig.xml</param-value>
</context-param>

上下文配置位置
dispatcherContext.xml securityConfig.xml

但是类路径呢,
类路径:
dispatcherContext.xml securityConfig.xml中缺失,但是得到了异常-->
org.springframework.beans.factory.BeanDefinitionStoreException:IOException从ServletContext资源[/securityConfig.xml]解析xml文档;嵌套异常为java.io.FileNotFoundException:无法打开ServletContext资源[/securityConfig.xml]
我已将
securityConfig.xml
放置在放置
dispatcherContext.xml
的同一位置,即在资源文件夹中,如果我删除
dispatcherContext.xml
,则
dispatcherContext.xml
将拾取,或者java类,如果在web.xml中执行基于java的conf.Mutlple上下文定义,将意味着不同的应用程序,但这实际上不是您想要的。
<!-- Load spring security related configuration -->
<import resource="classpath:securityConfig.xml"/>
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>dispatcherContext.xml securityConfig.xml</param-value>
</context-param>