Spring security with GAE

2019-04-16 20:41发布

I'm trying to implement Spring security for my GAE application however I'm getting this error:

No bean named 'springSecurityFilterChain' is defined

I added this configuration to my web.xml:

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

And in the application Context:

<!-- Configure security -->
<security:http auto-config="true">
    <security:intercept-url pattern="/**" access="ROLE_USER" />
</security:http>

<security:authentication-manager alias="authenticationManager">
    <security:authentication-provider>
        <security:user-service>
            <security:user name="jimi" password="jimi" authorities="ROLE_USER, ROLE_ADMIN" />
            <security:user name="bob" password="bob" authorities="ROLE_USER" />
        </security:user-service>
    </security:authentication-provider>  
</security:authentication-manager>

What could be causing the error?

1条回答
做个烂人
2楼-- · 2019-04-16 21:18

Even if you do not specify the contextConfigLocation in your web.xml, the context implementation uses the default location (with XmlWebApplicationContext: "/WEB-INF/applicationContext.xml").

So I think you already have one applicationContext.xml but did not specify in your web.xml, but Spring was able to load it for you. But now you have an additional security configuration in a separate file. So you need to specify the location of this new file applicationContext-security.xml like this in your web.xml:

This will take care of both the files:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext*.xml</param-value>
</context-param>

or you can specify individually as a comma or space separated list also like below:

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

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

Documentation: ContextLoader

查看更多
登录 后发表回答