My Spring Boot 애플리케이션은 두 개의 다른 데이터베이스에 연결해야합니다. 첫 번째 데이터베이스 (주)는 localhost 응용 프로그램과 동일한 서버에 설치되고 다른 데이터베이스 (보조)는 원격 서버에 설치되며 유지 관리, 백업, 테스트 등을 위해 항상 사용할 수있는 것은 아닙니다.스프링 부트와 하이버 네이트 : 데이터베이스에 연결할 수없는 경우에도 애플리케이션을 시작하십시오.
다음 구성 (application.properties)을 사용합니다.
# main connection
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost/?autoReconnect=true&verifyServerCertificate=false&useSSL=false&requireSSL=false
spring.datasource.username=emater
spring.datasource.password=emater
# Keep the connection alive if idle for a long time (needed in production)
spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1
# secondary connection
planejamento.datasource.driverClassName=com.mysql.jdbc.Driver
planejamento.datasource.url=jdbc:mysql://10.22.1.4/?verifyServerCertificate=false&useSSL=false&requireSSL=false
planejamento.datasource.username=emater
planejamento.datasource.password=emater
planejamento.datasource.testWhileIdle = false
#config hibernate
spring.jpa.hibernate.ddl-auto=none
spring.jpa.properties.hibernate.dialect=org.hibernate.spatial.dialect.mysql.MySQLSpatial56Dialect
spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate4.SpringSessionContext
spring.jpa.show-sql=true
spring.jpa.format-sql=true
spring.jpa.use-sql-comments=true
spring.jpa.hibernate.enable_lazy_load_no_trans=true
응용 프로그램을 초기화 할 때 최대 절전 모드는 두 데이터베이스에 모두 연결을 시도합니다. 두 번째 데이터베이스를 사용할 수없는 경우 예외가 throw되고 응용 프로그램 초기화가 중단됩니다.
응용 프로그램을 시작할 때 응용 프로그램이 중단되지 않도록 사용할 수있는 속성이 있습니까?
어떻게해야합니까?
기본 메소드에서 Exception을 잡아낼 수 있습니다. –
이 링크는 도움이 될 수 있습니다. https://docs.jboss.org/hibernate/orm/4.3/javadocs/org/hibernate/exception/JDBCConnectionException.html –
예가 있습니까? 내 응용 프로그램의 기본 메서드에서 '시도/catch'될 것이라고? 어떻게 될까요? –