Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- liquibase.user=abc
- liquibase.password=xyz
- liquibase.url=jdbc:postgresql://something.eu-west-1.rds.amazonaws.com:5432/app?ApplicationName=${appName}-liquibase
- liquibase.enabled=true
- liquibase.contexts=dev,postgres
- @Configuration
- public class LiquibaseDataSourceConfiguration {
- private static final Logger LOG = LoggerFactory.getLogger(LiquibaseDataSourceConfiguration.class);
- @Autowired
- private LiquibaseDataSourceProperties liquibaseDataSourceProperties;
- @LiquibaseDataSource
- @Bean
- public DataSource liquibaseDataSource() {
- DataSource ds = DataSourceBuilder.create()
- .username(liquibaseDataSourceProperties.getUser())
- .password(liquibaseDataSourceProperties.getPassword())
- .url(liquibaseDataSourceProperties.getUrl())
- .driverClassName(liquibaseDataSourceProperties.getDriver())
- .build();
- if (ds instanceof org.apache.tomcat.jdbc.pool.DataSource) {
- ((org.apache.tomcat.jdbc.pool.DataSource) ds).setInitialSize(1);
- ((org.apache.tomcat.jdbc.pool.DataSource) ds).setMaxActive(2);
- ((org.apache.tomcat.jdbc.pool.DataSource) ds).setMaxAge(1000);
- ((org.apache.tomcat.jdbc.pool.DataSource) ds).setMinIdle(0);
- ((org.apache.tomcat.jdbc.pool.DataSource) ds).setMinEvictableIdleTimeMillis(60000);
- } else {
- // warnings or exceptions, whatever you prefer
- }
- LOG.info("Initialized a datasource for {}", liquibaseDataSourceProperties.getUrl());
- return ds;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement