[Spring-Security] 스프링 시큐리티 설정Error creating bean with name ‘org.springframework.security.filterChains’

Spring Security 를 설정하려고 할때 (이 경우는 xml을 사용한 namespace). 다음과 같은 에러가 발생한다면 security-config.xml (파일명은 설정에 따라 다를 수 있음)에서 누락된 부분이 있기때문 입니다.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘org.springframework.security.filterChains’: Cannot resolve reference to bean ‘org.springframework.security.web.DefaultSecurityFilterChain#0’ while setting bean property ‘sourceList’ with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘org.springframework.security.web.DefaultSecurityFilterChain#0’: Cannot resolve reference to bean ‘org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0’ while setting constructor argument with key [5]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0’: Cannot resolve reference to bean ‘org.springframework.security.authentication.ProviderManager#0’ while setting bean property ‘authenticationManager’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘org.springframework.security.authentication.ProviderManager#0’: Cannot resolve reference to bean ‘org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0’ while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0’: FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named ‘org.springframework.security.authenticationManager’ is defined:
Did you forget to add a global
element to your configuration (with child elements)?
Alternatively you can use the authentication-manager-ref attribute on your
and elements.

마지막 메세지를 참고하면 설정에 무언가 빠졌다는 것을 알 수 있습니다.
여기에서는 security-config.xml 에 <authentication-manager>를 추가하는 것으로 해결 하겠습니다.

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans
	xmlns="http://www.springframework.org/schema/security"
	xmlns:beans="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
       http://www.springframework.org/schema/security
       http://www.springframework.org/schema/security/spring-security-4.2.xsd">
	<http auto-config="false">
        Something
	</http>
	<authentication-manager>
		<authentication-provider>
			<user-service>
				<user name="admin" password="123"
					authorities="ROLE_USER, ROLE_ADMIN" />
				<user name="guest" password="123" authorities="ROLE_USER" />
			</user-service>
		</authentication-provider>
	</authentication-manager>
</beans:beans>

admin, user는 예시로 등록하였으며 설정한 auth에 따라 다른 값을 넣으시면 됩니다.

댓글 남기기