mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
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:
parent
018310e478
commit
f1ecf53495
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user