1

当 Spring 处理配置文件名时,有一些默认值......

  • 在我的 web.xml 中注册 DispatcherServlet 时,Spring 默认查找名为<servletname>-servlet.xml的文件
  • 在我的 web.xml 中注册 ContextLoadListener 时,Spring 默认查找文件名 applicationContext.xml

因此我问:当我使用 Spring Security 时,Spring 会查找默认文件名吗?还是我总是必须通过<context-param> <param-name> contextConfigLocation </param-name>filename</param-value></context-param>...手动配置它???

4

2 回答 2

2

Spring Security 没有自己的应用程序上下文,它使用由ContextLoaderListener(ie applicationContext.xml) 创建的应用程序上下文。

因此,您应该将 Spring Security 配置放入applicationContext.xml,或者,如果您想放入单独的文件,则需要从以下位置导入该文件applicationContext.xml

<import resource = "security.xml" />

applicationContext.xml或在以下之外声明它contextConfigLocatoion <context-param>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>applicationContext.xml, security.xml</param-value>
</context-param>
于 2012-09-21T11:58:22.550 回答
0

Spring roo 这样做:

  • applicationContext.xml - 根上下文
  • applicationContext-security.xml - 安全配置
  • webmvc-config.xml - mvc/控制器等
于 2012-09-21T13:48:44.770 回答