0

So if i do this:

<servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml,/WEB-INF/spring-security.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

i get exception that No bean named 'springSecurityFilterChain' is defined

if i do this:

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

<servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

i get exception that /WEB-INF/spring-servlet.xml not found or could not be oppened.

However it works like this:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring-security.xml</param-value>
</context-param>

<servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

so why can't i specify both in the tag? what am i missing?

  • In the first example, you are defining your beans for your dispatcher servlet, and nothing more, you shall use ContextLoaderListner and add your Spring XML files as context-params. In the second example you does not mention any XML, then Dispatcher servlet falls back to default XML which does not exist. – Amir Pashazadeh Mar 30 '13 at 21:00

2 Answers2

0

The first exception you got is probably because you forgot to specify spring security filters.

<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>

Are you sure your other examples are working (even though they start without exceptions) ?

Krešimir Nesek
  • 5,302
  • 4
  • 29
  • 56
0

In the first example, you are defining your beans for your dispatcher servlet, and nothing more (there is no root application context which can be accessed by Spring Security). you shall use ContextLoaderListner and add your Spring XML files as context-params.

In the second example you does not mention any XML, then Dispatcher servlet falls back to default XML which does not exist.

In the third-example you define some beans as a root application context, and some beans as dispatcher servlet beans (you mention an XML name, so it does not fall back to default name).

Amir Pashazadeh
  • 7,170
  • 3
  • 39
  • 69