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
This commit is contained in:
@@ -50,7 +50,6 @@ class DataSourceInitializer implements ApplicationListener<DataSourceInitialized
|
||||
@Autowired
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
|
||||
@Autowired(required = false)
|
||||
private DataSource dataSource;
|
||||
|
||||
@Autowired
|
||||
@@ -59,11 +58,14 @@ class DataSourceInitializer implements ApplicationListener<DataSourceInitialized
|
||||
private boolean initialized = false;
|
||||
|
||||
@PostConstruct
|
||||
protected void initialize() {
|
||||
public void init() {
|
||||
if (!this.properties.isInitialize()) {
|
||||
logger.debug("Initialization disabled (not running DDL scripts)");
|
||||
return;
|
||||
}
|
||||
if (applicationContext.getBeanNamesForType(DataSource.class, false, false).length > 0) {
|
||||
this.dataSource = applicationContext.getBean(DataSource.class);
|
||||
}
|
||||
if (this.dataSource == null) {
|
||||
logger.debug("No DataSource found so not initializing");
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user