Commit a608e099 authored by Andy Wilkinson's avatar Andy Wilkinson

Merge branch '1.5.x'

parents 19b27944 e19400ba
/* /*
* Copyright 2012-2016 the original author or authors. * Copyright 2012-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -40,6 +40,7 @@ import org.springframework.boot.autoconfigure.condition.SpringBootCondition; ...@@ -40,6 +40,7 @@ import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
import org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerPostProcessor.Registrar; import org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerPostProcessor.Registrar;
import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvidersConfiguration; import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvidersConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Condition; import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext; import org.springframework.context.annotation.ConditionContext;
...@@ -57,6 +58,7 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; ...@@ -57,6 +58,7 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
* @author Dave Syer * @author Dave Syer
* @author Phillip Webb * @author Phillip Webb
* @author Stephane Nicoll * @author Stephane Nicoll
* @author Kazuki Shimizu
*/ */
@Configuration @Configuration
@ConditionalOnClass({ DataSource.class, EmbeddedDatabaseType.class }) @ConditionalOnClass({ DataSource.class, EmbeddedDatabaseType.class })
...@@ -69,8 +71,9 @@ public class DataSourceAutoConfiguration { ...@@ -69,8 +71,9 @@ public class DataSourceAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
public DataSourceInitializer dataSourceInitializer() { public DataSourceInitializer dataSourceInitializer(
return new DataSourceInitializer(); DataSourceProperties properties, ApplicationContext applicationContext) {
return new DataSourceInitializer(properties, applicationContext);
} }
/** /**
......
/* /*
* Copyright 2012-2016 the original author or authors. * Copyright 2012-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -26,10 +26,9 @@ import javax.sql.DataSource; ...@@ -26,10 +26,9 @@ import javax.sql.DataSource;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.config.ResourceNotFoundException; import org.springframework.boot.context.config.ResourceNotFoundException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.jdbc.config.SortedResourcesFactoryBean; import org.springframework.jdbc.config.SortedResourcesFactoryBean;
import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils; import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils;
...@@ -45,6 +44,7 @@ import org.springframework.util.StringUtils; ...@@ -45,6 +44,7 @@ import org.springframework.util.StringUtils;
* @author Phillip Webb * @author Phillip Webb
* @author Eddú Meléndez * @author Eddú Meléndez
* @author Stephane Nicoll * @author Stephane Nicoll
* @author Kazuki Shimizu
* @since 1.1.0 * @since 1.1.0
* @see DataSourceAutoConfiguration * @see DataSourceAutoConfiguration
*/ */
...@@ -52,16 +52,19 @@ class DataSourceInitializer implements ApplicationListener<DataSourceInitialized ...@@ -52,16 +52,19 @@ class DataSourceInitializer implements ApplicationListener<DataSourceInitialized
private static final Log logger = LogFactory.getLog(DataSourceInitializer.class); private static final Log logger = LogFactory.getLog(DataSourceInitializer.class);
@Autowired private final DataSourceProperties properties;
private ConfigurableApplicationContext applicationContext;
private DataSource dataSource; private final ApplicationContext applicationContext;
@Autowired private DataSource dataSource;
private DataSourceProperties properties;
private boolean initialized = false; private boolean initialized = false;
DataSourceInitializer(DataSourceProperties properties, ApplicationContext applicationContext) {
this.properties = properties;
this.applicationContext = applicationContext;
}
@PostConstruct @PostConstruct
public void init() { public void init() {
if (!this.properties.isInitialize()) { if (!this.properties.isInitialize()) {
......
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