잡동사니

반응형

질문

OK- problem == > Springboot Session을 사용할 때 2 개 이상의 데이터 소스로 인해 오류가 발생합니다.

다른 목적을 위해 다른 데이터 소스를 사용하는 Springboot 프로젝트가 있습니다. 그래서 상기 프로젝트 내에서 Spring이 HttpSession을 Spring-Session 모듈의 HttpSession으로 대체하도록하고 싶습니다.

가이드를 따르면 세션 테이블 생성이 간단합니다.하지만 가이드와 API 문서에 따르면 데이터 소스는 하나만 필요합니다. 따라서 2 개 이상이 있으므로 다음 오류가 발생합니다.

2020-07-21 21:38:59.134 ERROR 171262 --- [  restartedMain] o.s.b.web.embedded.tomcat.TomcatStarter  : 
Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. 
Message: Error creating bean with name 'sessionRepositoryFilterRegistration' defined in class path resource 
[org/springframework/boot/autoconfigure/session/SessionRepositoryFilterConfiguration.class]: 
Unsatisfied dependency expressed through method 'sessionRepositoryFilterRegistration' parameter 1; 
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with 
name 'org.springframework.session.jdbc.config.annotation.web.http.JdbcHttpSessionConfiguration': 
Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: 
No qualifying bean of type 'javax.sql.DataSource' available: 
expected single matching bean but found 2: authModelDs,secureSessionDS

따라서 어떤 것을 사용할지 결정할 수 없기 때문에 수동으로 구성해야합니다. 단, 전체 프로세스가
org.springframework.session.jdbc.config.annotation.web.http. JdbcHttpSessionConfiguration , 이는 자체 데이터 소스를 설정해야하는 주어진 요구에 따라 문자 그대로 구성 할 수 없습니다.

나는 조금 둘러 보았고 세션 필터를 구성 할 방법이 없습니다. 일단 데이터 소스를 대체하기 위해 생성되면 세션 필터도 구성 할 수 없습니다.

그래서 나는 당황했습니다. 구성된 Spring-Session에 대해 올바른 데이터 소스를 어떻게 설정할 수 있습니까?

어떤 도움을 주시면 감사하겠습니다.

 

답변1

아하! Soooooo

해당 Bean이 SpringBoot 세션 데이터 소스임을 지정하기 위해 데이터 소스의 Bean 생성에 배치 할 수 있는 주석이 있습니다.

주석은 - @SpringSessionDataSource 입니다.

문서에서 정말 간단하지 않습니다!

다음 스택 오버플로 답변에 대한 props :

스프링 부트 및 스프링 세션 : 제어 방법 데이터 소스



 

 

 

 

출처 : https://stackoverflow.com/questions/63023229/springboot-session-cannot-be-created-when-2-or-more-datasources-exist

반응형

이 글을 공유합시다

facebook twitter googleplus kakaoTalk kakaostory naver band