Update JpaBaseConfiguration to use constructor injection
This change was missed as part of the work done in 19d8c5e6
.
See gh-5306
Closes gh-5543
This commit is contained in:
parent
e41ccfae3c
commit
15cbef3df0
|
@ -25,6 +25,7 @@ import javax.sql.DataSource;
|
|||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
|
||||
|
@ -53,6 +54,7 @@ import org.springframework.util.ClassUtils;
|
|||
* @author Phillip Webb
|
||||
* @author Josh Long
|
||||
* @author Manuel Doninger
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass({ LocalContainerEntityManagerFactoryBean.class,
|
||||
|
@ -81,14 +83,10 @@ public class HibernateJpaAutoConfiguration extends JpaBaseConfiguration {
|
|||
"org.hibernate.engine.transaction.jta.platform.internal.WebSphereExtendedJtaPlatform",
|
||||
"org.hibernate.service.jta.platform.internal.WebSphereExtendedJtaPlatform", };
|
||||
|
||||
private final JpaProperties properties;
|
||||
|
||||
private final DataSource dataSource;
|
||||
|
||||
public HibernateJpaAutoConfiguration(JpaProperties properties,
|
||||
DataSource dataSource) {
|
||||
this.properties = properties;
|
||||
this.dataSource = dataSource;
|
||||
public HibernateJpaAutoConfiguration(DataSource dataSource,
|
||||
JpaProperties jpaProperties,
|
||||
ObjectProvider<JtaTransactionManager> jtaTransactionManagerProvider) {
|
||||
super(dataSource, jpaProperties, jtaTransactionManagerProvider);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -99,7 +97,7 @@ public class HibernateJpaAutoConfiguration extends JpaBaseConfiguration {
|
|||
@Override
|
||||
protected Map<String, Object> getVendorProperties() {
|
||||
Map<String, Object> vendorProperties = new LinkedHashMap<String, Object>();
|
||||
vendorProperties.putAll(this.properties.getHibernateProperties(this.dataSource));
|
||||
vendorProperties.putAll(getProperties().getHibernateProperties(getDataSource()));
|
||||
return vendorProperties;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -25,7 +25,7 @@ import javax.sql.DataSource;
|
|||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurationPackages;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
|
@ -57,6 +57,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
|
|||
* @author Phillip Webb
|
||||
* @author Dave Syer
|
||||
* @author Oliver Gierke
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@EnableConfigurationProperties(JpaProperties.class)
|
||||
@Import(DataSourceInitializedPublisher.Registrar.class)
|
||||
|
@ -64,19 +65,20 @@ public abstract class JpaBaseConfiguration implements BeanFactoryAware {
|
|||
|
||||
private static final String[] NO_PACKAGES = new String[0];
|
||||
|
||||
private final DataSource dataSource;
|
||||
|
||||
private final JpaProperties properties;
|
||||
|
||||
private final JtaTransactionManager jtaTransactionManager;
|
||||
|
||||
private ConfigurableListableBeanFactory beanFactory;
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
@Autowired(required = false)
|
||||
private PersistenceUnitManager persistenceUnitManager;
|
||||
|
||||
@Autowired
|
||||
private JpaProperties jpaProperties;
|
||||
|
||||
@Autowired(required = false)
|
||||
private JtaTransactionManager jtaTransactionManager;
|
||||
protected JpaBaseConfiguration(DataSource dataSource, JpaProperties properties,
|
||||
ObjectProvider<JtaTransactionManager> jtaTransactionManagerProvider) {
|
||||
this.dataSource = dataSource;
|
||||
this.properties = properties;
|
||||
this.jtaTransactionManager = jtaTransactionManagerProvider.getIfAvailable();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(PlatformTransactionManager.class)
|
||||
|
@ -88,20 +90,21 @@ public abstract class JpaBaseConfiguration implements BeanFactoryAware {
|
|||
@ConditionalOnMissingBean
|
||||
public JpaVendorAdapter jpaVendorAdapter() {
|
||||
AbstractJpaVendorAdapter adapter = createJpaVendorAdapter();
|
||||
adapter.setShowSql(this.jpaProperties.isShowSql());
|
||||
adapter.setDatabase(this.jpaProperties.getDatabase());
|
||||
adapter.setDatabasePlatform(this.jpaProperties.getDatabasePlatform());
|
||||
adapter.setGenerateDdl(this.jpaProperties.isGenerateDdl());
|
||||
adapter.setShowSql(this.properties.isShowSql());
|
||||
adapter.setDatabase(this.properties.getDatabase());
|
||||
adapter.setDatabasePlatform(this.properties.getDatabasePlatform());
|
||||
adapter.setGenerateDdl(this.properties.isGenerateDdl());
|
||||
return adapter;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public EntityManagerFactoryBuilder entityManagerFactoryBuilder(
|
||||
JpaVendorAdapter jpaVendorAdapter) {
|
||||
JpaVendorAdapter jpaVendorAdapter,
|
||||
ObjectProvider<PersistenceUnitManager> persistenceUnitManagerProvider) {
|
||||
EntityManagerFactoryBuilder builder = new EntityManagerFactoryBuilder(
|
||||
jpaVendorAdapter, this.jpaProperties.getProperties(),
|
||||
this.persistenceUnitManager);
|
||||
jpaVendorAdapter, this.properties.getProperties(),
|
||||
persistenceUnitManagerProvider.getIfAvailable());
|
||||
builder.setCallback(getVendorCallback());
|
||||
return builder;
|
||||
}
|
||||
|
@ -158,6 +161,22 @@ public abstract class JpaBaseConfiguration implements BeanFactoryAware {
|
|||
return (this.jtaTransactionManager != null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@link JpaProperties}.
|
||||
* @return the properties
|
||||
*/
|
||||
protected final JpaProperties getProperties() {
|
||||
return this.properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@link DataSource}.
|
||||
* @return the data source
|
||||
*/
|
||||
protected final DataSource getDataSource() {
|
||||
return this.dataSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
|
||||
this.beanFactory = (ConfigurableListableBeanFactory) beanFactory;
|
||||
|
|
Loading…
Reference in New Issue