org.springframework.beans.factory.NoSuchBeanDefinitionException: Aucun bob nommé 'springSecurityFilterChain' Configuration non définie basée sur Java

Tenter de permettre
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'springSecurityFilterChain' is defined

en configuration basée sur 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>


Sur la base 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;
}
}


Déposer SecurityConfig.java pour la sécurité:


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

public SecurityConfig// {
super//;
}

}


Et enfin classe 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>


Maintenant je reçois
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'springSecurityFilterChain' is defined

dans le projet Java base Spring Security, Sur lequel je travaille. Tout fonctionne bien avec la configuration des annotations et est parfaitement testé. Pour certaines raisons Spring does Donne une telle erreur lors de la tentative d'exécution d'un exemple de saisie du formulaire Spring Security.

aussi dans spring-security-config.xml J'ai essayé de changer
<http use-expressions="true">

sur
<http auto-config="true">

, Mais n'a toujours pas réussi à résoudre tout Bob nommé
'springSecurityFilterChain'

Exceptions trouvées.

Toute aide dans ce numéro sera très reconnaissante.
Remercier,
</http></http>
Invité:

Alice

Confirmation de:

Récipient Spring Essayer de trouver un composant springSecurityFilterChain Dans le contexte de l'application, et non dans le contexte de l'application Web. Changer la configuration spring security, Afin qu'il soit inclus dans le contexte racinaire.

Christine

Confirmation de:

Veuillez fournir une configuration minimale. spring-security

http://www.springframework.org/schémas/Haricots./Spring haricots-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>

Pour répondre aux questions, connectez-vous ou registre