특정 환경 변수가있을 때 특정 데이터 소스를 사용하도록 스프링 부트 애플리케이션을 구성하려고합니다. 예를 들어, 환경 변수가 MY_PROD_DATASOURCE
인 경우 프로덕션 데이터 소스를 사용하고 싶습니다. 그렇지 않으면 같은 유형의 로컬 데이터 소스를 사용하고 싶습니다.환경에 기반한 Spring 데이터 소스
application.properties
에서 하나의 데이터 소스를 선언하는 방법을 설명하는 something in the Spring reference을 발견했습니다. 특히, MySQL 데이터 소스는 다음과 같이 보일 수 있습니다 :
spring.datasource.url=jdbc:mysql://localhost/test
spring.datasource.username=dbuser
spring.datasource.password=dbpass
spring.datasource.driverClassName=com.mysql.jdbc.Driver
그러나이 파일에서 조건부로 데이터 소스 등록 정보를 변경할 수는 없습니다. 그것을 할 다른 방법이 있습니까? 당신이 할 수있는 봄 부팅에서
다른 데이터 소스 파일을 사용하여 여러 세션 팩토리를 정의 할 수 있습니다. http://stackoverflow.com/questions/20541736/hibernate-configuring-multiple-datasources-and-multiple-session-factories –
좀 더 자세히 설명해 주시겠습니까? 아마도 대답으로? – nmagerko