私のSpringブートアプリケーションは2つの異なるデータベースに接続する必要があります。最初のデータベース(main)は、localhostアプリケーションと同じサーバーにインストールされ、もう一方のデータベース(リモートサーバー)はリモートサーバー上にインストールされます(メンテナンス、バックアップ、テストなど)。Springブートと休止状態:データベースへの接続が利用できない場合でもアプリケーションを起動
次の設定(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
アプリケーションを初期化するとき、hibernateは両方のデータベースに接続しようとします。その時点で2番目のデータベースが使用できない場合、例外がスローされ、アプリケーションの初期化が中止されます。
起動時にアプリケーションの中断を防ぐために使用できるプロパティはありますか?
どうすればよいですか?
あなたのメインメソッドで例外をキャッチしようとすることができます。 –
このリンクは役に立ちますhttps://docs.jboss.org/hibernate/orm/4.3/javadocs/org/hibernate/exception/JDBCConnectionException.html –
例がありますか?私のアプリケーションの主な方法で '試してみる/キャッチする'のだろうか?それはどうですか? –