2016-07-15 273 views
0

我使用Spring Security,但由于某种原因,我的web.xml没有找到我的applicationContext .XML 的web.xmljava.io.FileNotFoundException:无法打开类路径资源[conf/admin/applicationContext.xml],因为它不存在

<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value> 
      classpath:conf/admin/applicationContext.xml 
      classpath:conf/admin/applicationContext-security.xml 
    </param-value> 
</context-param> 

<filter> 
    <filter-name>springSecurityFilterChain</filter-name> 
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 
</filter> 

<filter-mapping> 
    <filter-name>springSecurityFilterChain</filter-name> 
    <url-pattern>/*</url-pattern> 
</filter-mapping> 

<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 

我的applicationContext.xml是myProject的/ conf目录/管理/ applicationContext.xml中,在同一个地方作为我的web.xml但它总是抛出异常:

14:18:07,793 ERROR [ContextLoader] Context initialization failed 
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [conf/admin/applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [conf/admin/applicationContext.xml] cannot be opened because it does not exist 

我试过把WEB-INF文件夹放进去(就像每个Spring Security教程),这是在myProject/dist/web/WEB-INF,但是当我清理我的项目刷新和重建它被删除。

那么我做错了什么?把错误的路径放在contextConfigLocation或applicationContext.xml中错误的地方?

回答

1

假设您遵循Standard Maven Directory Structure即你的XML配置文件是src/main/webapp/WEB-INF/conf/admin下再试试这个:

<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value> 
     /WEB-INF/conf/admin/applicationContext.xml 
     /WEB-INF/conf/admin/applicationContext-security.xml 
    </param-value> 
</context-param> 

另一种方法是去与默认:

  1. 只需将您applicationContext.xml文件在src/main/webapp/WEB-INF下,它会在默认情况下在春季被选中。
  2. 然后,您可以在applicationContext.xml中添加此行<import resource="applicationContext-security.xml" />以导入安全配置。
  3. 使用默认配置方法检查Repository
+0

@StudioWorks如果回答您的问题,请接受此解决方案。 –

相关问题