收到异常:未定义名为"springSecurityFilterChain"的bean [英] getting exception: No bean named 'springSecurityFilterChain' is defined
问题描述
我正在从参考资料中学习弹簧安全性.发布3.1.2.RELEASE.如前所述,我已经像这样配置了security:http
标记
I am learning spring security from reference material. release 3.1.2.RELEASE. As stated in that I have configured security:http
tag like this
security-context.xml
<security:http auto-config="true">
<security:intercept-url pattern="/**" access="ROLE_USER"/>
</security:http>
web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:*-context.xml</param-value>
</context-param>
<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>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>security</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>security</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
security-servlet.xml
<context:component-scan base-package="com.pokuri.security.mvc.controllers"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/page/"/>
<property name="suffix" value=".jsp"/>
</bean>
但是启动应用程序时出现此异常.如果删除安全配置,我的spring Web应用程序将正常运行.我在stackoverflow中也遇到了同样的问题.但没有运气.
But I am getting this exception when I start the application. If I remove security configuration my spring web application working fine. I went through the same kind of questions in stackoverflow. But no luck.
推荐答案
我认为问题的原因可能在于启动Web应用程序时未加载用于弹簧安全性的xml配置文件.
I think that the reason of your problem can be in that your xml configuration file for spring security isn't loaded when you start your web app.
要解决此问题,您应该像这样在web.xml中指定所有XML配置文件:
To fix this you should specify all your XML config files in web.xml like that:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-security.xml, /WEB-INF/applicationContext.xml</param-value>
</context-param>
如果您的配置文件位于类路径(不是WEB-INF文件夹或其子文件夹)中,则可以通过这种方式指定配置文件列表;
If you have your config files in classpath (not WEB-INF folder or it's subfolders) then you can specify list of config files in such way;
...
<param-value>
classpath:applicationContext.xml,
classpath:spitter-security.xml
</param-value>
...
另外,您还需要添加特殊的侦听器来加载配置文件:
And also you need to add special listener that will load your config files:
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
这篇关于收到异常:未定义名为"springSecurityFilterChain"的bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!