开发者

Multiple config files for Spring Security

I'm quite new to all things Spring, and rig开发者_如何学编程ht now I'm developing an application that uses Spring, Spring MVC and 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?.


This answer relates to springframework 2.5.6, it might have changed in later versions.

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>

If you do not set the contextConfigLocation it defaults to handler-servlet.xml (at least in this example).

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>

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜