티스토리 뷰

org.springframework.security.filterChains

 

web.xml

->해당 오류는 필터가 등록이 된 후 bean을 등록하고 시큐리티 설정파일을 읽어야하는데

보동 저 xml 설정파일을 위에 같이 적는 경우가 많았다 밑으로 빼주니 해결. 빈등록 후 설정파일을 읽음. 

 

servlet-context.xml

org.springframework.beans.factory.BeanCreationException

-> context:component-scan과 dao에서 @Repository를 같이 혼용하여 사용하는 경우

빈이 2번 등록된다. 따라서 둘 중 하나만 사용하도록 하자...

나는 context-component를 주석처리 하였다 물려받은 프로젝트 모두 dao에 @Repository가 적혀있었기 때문에..

 

참고 : servlet-context에서는 controller annotation만 등록하고 나머지(service, repository, component 등)는 spring bean으로 등록하지 않는다.

use-default-filters="false" 로 설정하면 표기되지 않은 나머지(service, repository, component 등)는 spring bean으로 등록하지 않는다는 뜻이다.

 

https://okky.kr/article/551253?note=1627415 참고

 

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain'

-> servlet-context.xml에 빈을 등록해주자.

**

예외

**

 

기존 프로젝트에 스프링 시큐리티를 입히려고 하루 반 정도를 날렸다.

여러가지 오류들 중 가장 큰 원인이라고 생각되는것은 스프링 프레임워크 버전과 스프링 시큐리티 버전이 일치해야한다는 것 같다.

pom.xml에서 스프링 프레임워크 4 버전이라고 예를들면 시큐리티도 4버전과 호환되는 버전으로 맞춰줘야한다.

또한 servlet-context.xml에서 

<!-- 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
		  /WEB-INF/spring/spring-security.xml
		  classpath*:config/spring/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>

이처럼 contextConfigLocation 의 value 값을 한 번에 적어주고 filter들은 위에서 먼저 한번에 선언 후 적자 

(인코딩 관련 필터는 제일 먼저 적어주고 그 다음으로 시큐리티 filter들을 선언해야한다.)

 

사이트 참고

 

gmlwjd9405.github.io/2019/01/03/spring-security.html

 

[Spring] Spring Security - Heee's Development Blog

Step by step goes a long way.

gmlwjd9405.github.io

to-dy.tistory.com/70

 

Spring Security - 기본 설정 (완전 기초)

1. 라이브러리 추가 Spring Security는 Spring 버전에 의존도가 있기 때문에, 의존성(dependency) 관련 버전을 반드시 확인하고 사용해야 한다. 무조건 내가 쓴 버전을 사용해야 한다는 것이 아니다. 의존

to-dy.tistory.com