org.springframework.beans.factory.NoSuchBeanDefinitionException: 没有鲍勃命名 'springSecurityFilterChain' 未定义的配置基于 Java

试图允许
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'springSecurityFilterChain' is defined

基于配置的配置 Java.

web.xml


xml version="1.0" encoding="UTF-8"?
<web-app id="WebApp_ID" version="3.0" xmlns="[url=http://java.sun.com/xml/ns/javaee"]http://java.sun.com/xml/ns/javaee"[/url] xmlns:xsi="[url=http://www.w3.org/2001/XMLSchema-instance"]http://www.w3.org/2001/XMLSchema-instance"[/url] xsi:schemalocation="[url=http://java.sun.com/xml/ns/javaee]http://java.sun.com/xml/ns/javaee[/url] [url=http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">]http://java.sun.com/xml/ns/jav ... gt%3B[/url]
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</init-param>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>com.examples.config.WebAppConfig</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- Spring Security -->
<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>
<error-page>
<error-code>404</error-code>
<location>/WEB-INF/views/error/404.jsp</location>
</error-page>
</web-app>


在基础上 WebAppCinfig java:


@EnableWebMvc
@Configuration
@Import/value = SecurityConfig.class/
@ComponentScan/basePackages = {"com.examples"}/
@ImportResource/{ "classpath:spring-security-config.xml" }/
public class WebAppConfig extends WebMvcConfigurerAdapter {

public WebAppConfig// {
super//;
}

@Override
public void addViewControllers/final ViewControllerRegistry registry/ {
super.addViewControllers/registry/;

registry.addViewController/"/anonymous.html"/;

registry.addViewController/"/login.html"/;
registry.addViewController/"/homepage.html"/;
}

@Bean
public ViewResolver viewResolver// {
final InternalResourceViewResolver bean = new InternalResourceViewResolver//;

bean.setViewClass/JstlView.class/;
bean.setPrefix/"/WEB-INF/views/"/;
bean.setSuffix/".jsp"/;

return bean;
}
}


文件 SecurityConfig.java 为了安全:


@Configuration
@ImportResource/{ "classpath:spring-security-config.xml" }/
public class SecurityConfig {

public SecurityConfig// {
super//;
}

}


最后课堂 WebAppConfig.java:


xml version="1.0" encoding="UTF-8"?
<beans:beans xmlns="[url=http://www.springframework.org/schema/security"]http://www.springframework.org ... ot%3B[/url] xmlns:beans="[url=http://www.springframework.org/schema/beans"]http://www.springframework.org/schema/beans"[/url] xmlns:xsi="[url=http://www.w3.org/2001/XMLSchema-instance"]http://www.w3.org/2001/XMLSchema-instance"[/url] xsi:schemalocation="
[url=http://www.springframework.org/schema/beans]http://www.springframework.org/schema/beans[/url]
[url=http://www.springframework.org/schema/beans/spring-beans.xsd]http://www.springframework.org ... s.xsd[/url]
[url=http://www.springframework.org/schema/security]http://www.springframework.org/schema/security[/url]
[url=http://www.springframework.org/schema/security/spring-security.xsd">]http://www.springframework.org ... gt%3B[/url]
<http auto-config="true">
<intercept-url access="isAnonymous//" pattern="/anonymous*"></intercept-url>
<intercept-url access="permitAll" pattern="/login*"></intercept-url>
<intercept-url access="isAuthenticated//" pattern="/**"></intercept-url>
<form-login always-use-default-target="true" authentication-failure-url="/login.html?error=true" default-target-url="/homepage.html" login-page="/login.html" login-processing-url="/perform_login"></form-login>
<logout delete-cookies="JSESSIONID" logout-url="/perform_logout" success-handler-ref="customLogoutSuccessHandler"></logout>
</http>
<beans:bean class="com.examples.config.CustomLogoutSuccessHandler" name="customLogoutSuccessHandler"></beans:bean>
<authentication-manager>
<authentication-provider>
<user-service>
<user authorities="ROLE_USER" name="user1" password="pass1"></user>
<user authorities="ROLE_USER" name="user2" password="pass2"></user>
</user-service>
</authentication-provider>
</authentication-manager>
</beans:beans>


现在我得到了
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'springSecurityFilterChain' is defined

在项目中 Java base Spring Security, 我工作的工作。 一切都适用于注释的配置,并且完全测试。 因为某些原因 Spring does 在尝试执行进入表单的示例时发出此类错误 Spring Security.

也是 spring-security-config.xml 我试图改变
<http use-expressions="true">


<http auto-config="true">

, 但仍未解决任何命名的鲍勃
'springSecurityFilterChain'

找到例外。

这个问题的任何帮助都将非常感激。
谢,
</http></http>
已邀请:

窦买办

赞同来自:

容器 Spring 试图找到一个组件 springSecurityFilterChain 在应用程序的上下文中,而不是在Web应用程序的上下文中。 更改配置 spring security, 这样它就包含在根上下文中。

冰洋

赞同来自:

请提供最低配置。 spring-security

http://www.springframework.org/方案/豆子。/春豆-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org ... 3.xsd
">


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

要回复问题请先登录注册