用于Spring Security的多个配置文件 [英] Multiple config files for Spring Security

查看:332
本文介绍了用于Spring Security的多个配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Spring的所有事物都比较陌生,现在我正在开发一个使用Spring,Spring MVC和Spring Security的应用程序。

I'm quite new to all things Spring, and right now I'm developing an application that uses Spring, Spring MVC and Spring Security.

我的问题是我正在使用两个调度程序Servlet,一个用于/csm/*.html,另一个用于* .html,我想使用一个每个servlet的Spring Security配置文件。

My problem is that I'm using two dispatcher Servlets, one for /csm/*.html and another one for *.html and I'd like to have one Spring Security configuration file per servlet.

这有可能吗?如果可以,您能给我一个例子吗?

Is this possible at all?, if so, could you point me to an example?.

推荐答案

此答案与springframework 2.5.6有关,在更高版本中可能已更改。

使用模式 / WEB-INF / [servlet-name] -servlet.xml 或在web.xml中指定如下:

use the pattern /WEB-INF/[servlet-name]-servlet.xml or specify it in the web.xml like this:

<servlet>
    <servlet-name>handler</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
    <!-- override default name {servlet-name}-servlet.xml -->
    <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring-myconfig.xml</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
</servlet>

如果不设置 contextConfigLocation

应用程序范围内的东西属于 /WEB-INF/applicationContext.xml
但您也可以更改默认值,甚至可以添加多个文件:

application wide stuff belongs into /WEB-INF/applicationContext.xml. But you also can change the default and even add multiple files:

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

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        WEB-INF/spring-dao-hibernate.xml,
        WEB-INF/spring-services.xml,
        WEB-INF/spring-security.xml
    </param-value>
</context-param>

您可以在spring网站上找到更具体的答案,文档非常好。

you can find a more specific answer on the spring website, the documentation is quite good.

这篇关于用于Spring Security的多个配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆