diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.java index 3a71b5cd9c..b3889f25bf 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.java @@ -16,29 +16,18 @@ package org.springframework.boot.autoconfigure.orm.jpa; -import java.util.Arrays; - import javax.persistence.EntityManager; +import org.hibernate.engine.spi.SessionImplementor; + import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.condition.ConditionMessage; -import org.springframework.boot.autoconfigure.condition.ConditionMessage.Style; -import org.springframework.boot.autoconfigure.condition.ConditionOutcome; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.SpringBootCondition; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; -import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration.HibernateEntityManagerCondition; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.ConditionContext; -import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; -import org.springframework.core.Ordered; -import org.springframework.core.annotation.Order; -import org.springframework.core.type.AnnotatedTypeMetadata; import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; -import org.springframework.util.ClassUtils; /** * {@link EnableAutoConfiguration Auto-configuration} for Hibernate JPA. @@ -49,31 +38,10 @@ import org.springframework.util.ClassUtils; * @author Andy Wilkinson */ @Configuration(proxyBeanMethods = false) -@ConditionalOnClass({ LocalContainerEntityManagerFactoryBean.class, EntityManager.class }) -@Conditional(HibernateEntityManagerCondition.class) +@ConditionalOnClass({ LocalContainerEntityManagerFactoryBean.class, EntityManager.class, SessionImplementor.class }) @EnableConfigurationProperties(JpaProperties.class) @AutoConfigureAfter({ DataSourceAutoConfiguration.class }) @Import(HibernateJpaConfiguration.class) public class HibernateJpaAutoConfiguration { - @Order(Ordered.HIGHEST_PRECEDENCE + 20) - static class HibernateEntityManagerCondition extends SpringBootCondition { - - private static final String[] CLASS_NAMES = { "org.hibernate.ejb.HibernateEntityManager", - "org.hibernate.jpa.HibernateEntityManager" }; - - @Override - public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { - ConditionMessage.Builder message = ConditionMessage.forCondition("HibernateEntityManager"); - for (String className : CLASS_NAMES) { - if (ClassUtils.isPresent(className, context.getClassLoader())) { - return ConditionOutcome.match(message.found("class").items(Style.QUOTE, className)); - } - } - return ConditionOutcome - .noMatch(message.didNotFind("class", "classes").items(Style.QUOTE, Arrays.asList(CLASS_NAMES))); - } - - } - }