diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.java index 5bb05bd031..09a9dccc3a 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.java @@ -54,6 +54,10 @@ public class HibernateJpaAutoConfiguration extends JpaBaseConfiguration implemen private ClassLoader classLoader; + public HibernateJpaAutoConfiguration() { + System.err.println("Init"); + } + @Override public void setBeanClassLoader(ClassLoader classLoader) { this.classLoader = classLoader; diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfiguration.java index c98562c961..eeac2efa09 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfiguration.java @@ -43,6 +43,7 @@ import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.WebSecurity; import org.springframework.security.config.annotation.web.builders.WebSecurity.IgnoredRequestConfigurer; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer; import org.springframework.security.web.AuthenticationEntryPoint; @@ -80,7 +81,7 @@ import org.springframework.security.web.util.matcher.AnyRequestMatcher; @Configuration @EnableConfigurationProperties @ConditionalOnClass({ EnableWebSecurity.class }) -@ConditionalOnMissingBean(annotation = EnableWebSecurity.class) +@ConditionalOnMissingBean(WebSecurityConfiguration.class) public class SecurityAutoConfiguration { private static List DEFAULT_IGNORED = Arrays.asList("/css/**", "/js/**", diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfigurationTests.java index b7c5cd63bc..68bb1846ff 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfigurationTests.java @@ -19,12 +19,19 @@ package org.springframework.boot.autoconfigure.security; import org.junit.Test; import org.springframework.boot.TestUtils; import org.springframework.boot.autoconfigure.AutoConfigurationReportLoggingInitializer; +import org.springframework.boot.autoconfigure.ComponentScanDetector; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; +import org.springframework.boot.autoconfigure.orm.jpa.test.City; import org.springframework.boot.context.initializer.LoggingApplicationContextInitializer; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.mock.web.MockServletContext; +import org.springframework.orm.jpa.JpaTransactionManager; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.TestingAuthenticationToken; import org.springframework.security.core.Authentication; @@ -93,6 +100,20 @@ public class SecurityAutoConfigurationTests { this.context.getBean(AuthenticationManager.class)); } + @Test + public void testJpaCoexistsHappily() throws Exception { + this.context = new AnnotationConfigWebApplicationContext(); + this.context.setServletContext(new MockServletContext()); + this.context.register(EntityConfiguration.class, TestConfiguration.class, + PropertyPlaceholderAutoConfiguration.class, + DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class, + SecurityAutoConfiguration.class); + // This can fail if security @Conditionals force early instantiation of the + // HibernateJpaAutoConfiguration + this.context.refresh(); + assertNotNull(this.context.getBean(JpaTransactionManager.class)); + } + private static AnnotationConfigWebApplicationContext debugRefresh( AnnotationConfigWebApplicationContext context) { TestUtils.addEnviroment(context, "debug:true"); @@ -105,6 +126,13 @@ public class SecurityAutoConfigurationTests { return context; } + @Configuration + @ComponentScan(basePackageClasses = { City.class }) + @Import(ComponentScanDetector.class) + protected static class EntityConfiguration { + + } + @Configuration protected static class TestConfiguration {