mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-05 00:56:58 +08:00
Re-order spring.factories so vanilla JPA users get component scan detection
This commit is contained in:
parent
50f3a2c614
commit
369b0834a0
@ -34,7 +34,7 @@ import org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean;
|
||||
@Configuration
|
||||
@ConditionalOnClass(JpaRepository.class)
|
||||
@ConditionalOnMissingBean(JpaRepositoryFactoryBean.class)
|
||||
@Import({ JpaComponentScanDetector.class, JpaRepositoriesAutoConfigureRegistrar.class })
|
||||
@Import(JpaRepositoriesAutoConfigureRegistrar.class)
|
||||
public class JpaRepositoriesAutoConfiguration {
|
||||
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* Configuration for a Commons DBCP database pool. The DBCP pool is popular but not
|
||||
* recommended in high volume environments.
|
||||
* recommended in high volume environments (the Tomcat DataSource is more reliable).
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
|
@ -82,7 +82,7 @@ public class DataSourceAutoConfiguration {
|
||||
|
||||
@Configuration
|
||||
@Conditional(DataSourceAutoConfiguration.SomeDatabaseCondition.class)
|
||||
// FIXME: make this @ConditionalOnBean(DataSorce.class)
|
||||
// FIXME: make this @ConditionalOnBean(DataSource.class)
|
||||
protected static class JdbcTemplateConfiguration {
|
||||
|
||||
@Autowired(required = false)
|
||||
|
@ -20,16 +20,19 @@ import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.ejb.HibernateEntityManager;
|
||||
import org.springframework.bootstrap.autoconfigure.jdbc.EmbeddedDatabaseConfiguration;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.bootstrap.context.annotation.ConditionalOnClass;
|
||||
import org.springframework.bootstrap.context.annotation.EnableAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
||||
import org.springframework.orm.jpa.JpaVendorAdapter;
|
||||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
||||
import org.springframework.orm.jpa.vendor.Database;
|
||||
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* {@link EnableAutoConfiguration Auto-configuration} for Hibernate JPA.
|
||||
@ -39,6 +42,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
@Configuration
|
||||
@ConditionalOnClass(HibernateEntityManager.class)
|
||||
@EnableTransactionManagement
|
||||
@Import(JpaComponentScanDetector.class)
|
||||
public class HibernateJpaAutoConfiguration extends JpaAutoConfiguration {
|
||||
|
||||
private static final Map<EmbeddedDatabaseType, String> EMBEDDED_DATABASE_DIALECTS;
|
||||
@ -48,24 +52,36 @@ public class HibernateJpaAutoConfiguration extends JpaAutoConfiguration {
|
||||
"org.hibernate.dialect.HSQLDialect");
|
||||
}
|
||||
|
||||
@Value("${spring.jpa.databasePlatform:${spring.jpa.database_platform:}}")
|
||||
private String databasePlatform;
|
||||
|
||||
@Value("${spring.jpa.database:DEFAULT}")
|
||||
private Database database = Database.DEFAULT;
|
||||
|
||||
@Value("${spring.jpa.showSql:${spring.jpa.show_sql:false}}")
|
||||
private boolean showSql;
|
||||
|
||||
@Value("${spring.jpa.generateDdl:${spring.jpa.generate_ddl:false}}")
|
||||
private boolean generateDdl;
|
||||
|
||||
@Bean
|
||||
@Override
|
||||
public JpaVendorAdapter jpaVendorAdapter() {
|
||||
return new HibernateJpaVendorAdapter();
|
||||
HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
|
||||
adapter.setShowSql(this.showSql);
|
||||
adapter.setGenerateDdl(this.generateDdl);
|
||||
if (StringUtils.hasText(this.databasePlatform)) {
|
||||
adapter.setDatabasePlatform(this.databasePlatform);
|
||||
}
|
||||
adapter.setDatabase(this.database);
|
||||
return adapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(
|
||||
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean) {
|
||||
Map<String, Object> properties = entityManagerFactoryBean.getJpaPropertyMap();
|
||||
if (isAutoConfiguredDataSource()) {
|
||||
properties.put("hibernate.hbm2ddl.auto", "create-drop");
|
||||
String dialect = EMBEDDED_DATABASE_DIALECTS
|
||||
.get(EmbeddedDatabaseConfiguration.getEmbeddedDatabaseType());
|
||||
if (dialect != null) {
|
||||
properties.put("hibernate.dialect", dialect);
|
||||
}
|
||||
}
|
||||
// FIXME: detect EhCache
|
||||
properties.put("hibernate.cache.provider_class",
|
||||
"org.hibernate.cache.HashtableCacheProvider");
|
||||
}
|
||||
|
@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.bootstrap.autoconfigure.data;
|
||||
package org.springframework.bootstrap.autoconfigure.orm.jpa;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@ -30,6 +30,7 @@ import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.bootstrap.autoconfigure.data.JpaRepositoriesAutoConfiguration;
|
||||
import org.springframework.bootstrap.context.annotation.AutoConfigurationUtils;
|
||||
import org.springframework.cglib.proxy.Enhancer;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
@ -1,10 +1,10 @@
|
||||
org.springframework.bootstrap.context.annotation.EnableAutoConfiguration=\
|
||||
org.springframework.bootstrap.autoconfigure.PropertyPlaceholderAutoConfiguration,\
|
||||
org.springframework.bootstrap.autoconfigure.MessageSourceAutoConfiguration,\
|
||||
org.springframework.bootstrap.autoconfigure.data.JpaRepositoriesAutoConfiguration,\
|
||||
org.springframework.bootstrap.autoconfigure.jdbc.DataSourceAutoConfiguration,\
|
||||
org.springframework.bootstrap.autoconfigure.batch.BatchAutoConfiguration,\
|
||||
org.springframework.bootstrap.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration,\
|
||||
org.springframework.bootstrap.autoconfigure.data.JpaRepositoriesAutoConfiguration,\
|
||||
org.springframework.bootstrap.autoconfigure.batch.BatchAutoConfiguration,\
|
||||
org.springframework.bootstrap.autoconfigure.thymeleaf.ThymeleafAutoConfiguration,\
|
||||
org.springframework.bootstrap.autoconfigure.web.EmbeddedContainerCustomizerConfiguration,\
|
||||
org.springframework.bootstrap.autoconfigure.web.EmbeddedJettyAutoConfiguration,\
|
||||
|
@ -18,6 +18,8 @@ package org.springframework.bootstrap.autoconfigure.data;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.bootstrap.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.bootstrap.autoconfigure.data.test.City;
|
||||
import org.springframework.bootstrap.autoconfigure.data.test.CityRepository;
|
||||
import org.springframework.bootstrap.autoconfigure.jdbc.EmbeddedDatabaseConfiguration;
|
||||
import org.springframework.bootstrap.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
|
||||
@ -40,9 +42,9 @@ public class JpaRepositoriesAutoConfigurationTests {
|
||||
public void testDefaultRepositoryConfiguration() throws Exception {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.register(TestConfiguration.class,
|
||||
EmbeddedDatabaseConfiguration.class,
|
||||
EmbeddedDatabaseConfiguration.class, HibernateJpaAutoConfiguration.class,
|
||||
JpaRepositoriesAutoConfiguration.class,
|
||||
HibernateJpaAutoConfiguration.class);
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
assertNotNull(this.context.getBean(CityRepository.class));
|
||||
assertNotNull(this.context.getBean(PlatformTransactionManager.class));
|
||||
@ -50,7 +52,7 @@ public class JpaRepositoriesAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ComponentScan("org.springframework.bootstrap.autoconfigure.data.test")
|
||||
@ComponentScan(basePackageClasses = City.class)
|
||||
protected static class TestConfiguration {
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user