、
私はアプリケーションにDBの特性が含まれており、次にデータソースBeanの@RefreshScopeを使用してプロパティをリフレッシュ外部スプリング設定ファイルを与えています。
スレッドがファイルの変更を監視し、アクチュエータのrefresh()メソッドを呼び出します。
データベース。プロパティデータソースの作成
dburl=jdbc://localhost:5432/dbname
dbusername=user1
dbpassword=userpwd
、
アプリケーションに外部の設定ファイルを与える
@RefreshScope
public class DBPropRefresh{
@Value("${dburl}")
private String dbUrl;
@Value("${dbusername}")
private String dbUserName;
@Value("${dbpassword}")
private String dbPassword;
@Bean
@RefreshScope
public DataSource getDatasource(){
return new DatasourceBuilder().create().url(dbUrl).username(dbUserName).password(dbPassword);
}
、
java -jar myapplication.jar --spring.config.location=database.properties
私は、database.propertiesファイルの変更を監視するために、Javaスレッドクラスを作成しました。続きを読むhttps://dzone.com/articles/how-watch-file-system-changes 変更があると、refreshEndPoint.refresh()を呼び出します。 pom.xmlで
、
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>1.5.6.RELEASE</version>
</dependency>
このhttps://stackoverflow.com/questions/44716195/refresh-database-configuration-on-the-fly/44717728#44717728 –