Commit f1ecf534 authored by Dave Syer's avatar Dave Syer

Delay instantiation of DataSource as late as possible

Unfortunately it still has to happen in a @PostConstruct (otherwise
JPA never sees the schema in time), but we can delay a bit by not
using @Autowired. Appears to fix the Spring Cloud problem
(https://github.com/spring-cloud/spring-cloud-config/issues/105).

Fixes gh-2658
parent 018310e4
...@@ -50,7 +50,6 @@ class DataSourceInitializer implements ApplicationListener<DataSourceInitialized ...@@ -50,7 +50,6 @@ class DataSourceInitializer implements ApplicationListener<DataSourceInitialized
@Autowired @Autowired
private ConfigurableApplicationContext applicationContext; private ConfigurableApplicationContext applicationContext;
@Autowired(required = false)
private DataSource dataSource; private DataSource dataSource;
@Autowired @Autowired
...@@ -59,11 +58,14 @@ class DataSourceInitializer implements ApplicationListener<DataSourceInitialized ...@@ -59,11 +58,14 @@ class DataSourceInitializer implements ApplicationListener<DataSourceInitialized
private boolean initialized = false; private boolean initialized = false;
@PostConstruct @PostConstruct
protected void initialize() { public void init() {
if (!this.properties.isInitialize()) { if (!this.properties.isInitialize()) {
logger.debug("Initialization disabled (not running DDL scripts)"); logger.debug("Initialization disabled (not running DDL scripts)");
return; return;
} }
if (applicationContext.getBeanNamesForType(DataSource.class, false, false).length > 0) {
this.dataSource = applicationContext.getBean(DataSource.class);
}
if (this.dataSource == null) { if (this.dataSource == null) {
logger.debug("No DataSource found so not initializing"); logger.debug("No DataSource found so not initializing");
return; return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment