diff --git a/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/data/JpaRepositoriesAutoConfiguration.java b/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/data/JpaRepositoriesAutoConfiguration.java index 0528b949cf..46aa141359 100644 --- a/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/data/JpaRepositoriesAutoConfiguration.java +++ b/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/data/JpaRepositoriesAutoConfiguration.java @@ -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 { } diff --git a/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/jdbc/BasicDataSourceConfiguration.java b/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/jdbc/BasicDataSourceConfiguration.java index c2619b00ff..1516ac81b6 100644 --- a/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/jdbc/BasicDataSourceConfiguration.java +++ b/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/jdbc/BasicDataSourceConfiguration.java @@ -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 * diff --git a/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/jdbc/DataSourceAutoConfiguration.java b/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/jdbc/DataSourceAutoConfiguration.java index f204b86e19..a934cb228d 100644 --- a/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/jdbc/DataSourceAutoConfiguration.java +++ b/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/jdbc/DataSourceAutoConfiguration.java @@ -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) diff --git a/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.java b/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.java index 20f030e075..67b9d45d2d 100644 --- a/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.java +++ b/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.java @@ -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 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 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"); } diff --git a/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/data/JpaComponentScanDetector.java b/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/orm/jpa/JpaComponentScanDetector.java similarity index 97% rename from spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/data/JpaComponentScanDetector.java rename to spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/orm/jpa/JpaComponentScanDetector.java index 214d694c8c..27f4afb34f 100644 --- a/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/data/JpaComponentScanDetector.java +++ b/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/orm/jpa/JpaComponentScanDetector.java @@ -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; diff --git a/spring-bootstrap/src/main/resources/META-INF/spring.factories b/spring-bootstrap/src/main/resources/META-INF/spring.factories index 7cc6c2e41f..ffa58f4d1d 100644 --- a/spring-bootstrap/src/main/resources/META-INF/spring.factories +++ b/spring-bootstrap/src/main/resources/META-INF/spring.factories @@ -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,\ diff --git a/spring-bootstrap/src/test/java/org/springframework/bootstrap/autoconfigure/data/JpaRepositoriesAutoConfigurationTests.java b/spring-bootstrap/src/test/java/org/springframework/bootstrap/autoconfigure/data/JpaRepositoriesAutoConfigurationTests.java index 74c35e1619..54425c0dc5 100644 --- a/spring-bootstrap/src/test/java/org/springframework/bootstrap/autoconfigure/data/JpaRepositoriesAutoConfigurationTests.java +++ b/spring-bootstrap/src/test/java/org/springframework/bootstrap/autoconfigure/data/JpaRepositoriesAutoConfigurationTests.java @@ -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 { }