Let’s assume you’re using Flyway as database migration tool. If your DBA does not give out credentials that allows you to alter the schema or issuing DDL statements, you have to configure a second database that tracks the Flyway migrations. Here it is without any further explanations how to configure a second database in Spring. Both databases can be configured in the application.properties. The @FlywayDataSource annotation is provided by Spring to set the database for Flyway.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
public class PersistenceConfiguration { | |
@Bean | |
@ConfigurationProperties(prefix="spring.datasource") | |
@Primary | |
public DataSource dataSource() { | |
return DataSourceBuilder.create().build(); | |
} | |
@Bean | |
@ConfigurationProperties(prefix="flyway.datasource") | |
@FlywayDataSource | |
public DataSource dataSource() { | |
return DataSourceBuilder.create().build(); | |
} | |
} |