File tree Expand file tree Collapse file tree 2 files changed +13
-0
lines changed
spring-boot-project/spring-boot-test-autoconfigure/src
main/java/org/springframework/boot/test/autoconfigure/jdbc
test/java/org/springframework/boot/test/autoconfigure/jdbc Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change 2424import org .apache .commons .logging .Log ;
2525import org .apache .commons .logging .LogFactory ;
2626
27+ import org .springframework .aot .AotDetector ;
2728import org .springframework .beans .BeansException ;
2829import org .springframework .beans .factory .FactoryBean ;
2930import org .springframework .beans .factory .InitializingBean ;
@@ -83,6 +84,9 @@ static class EmbeddedDataSourceBeanFactoryPostProcessor implements BeanDefinitio
8384
8485 @ Override
8586 public void postProcessBeanDefinitionRegistry (BeanDefinitionRegistry registry ) throws BeansException {
87+ if (AotDetector .useGeneratedArtifacts ()) {
88+ return ;
89+ }
8690 Assert .isInstanceOf (ConfigurableListableBeanFactory .class , registry ,
8791 "Test Database Auto-configuration can only be used with a ConfigurableListableBeanFactory" );
8892 process (registry , (ConfigurableListableBeanFactory ) registry );
Original file line number Diff line number Diff line change 2121import org .junit .jupiter .api .Test ;
2222
2323import org .springframework .boot .autoconfigure .AutoConfigurations ;
24+ import org .springframework .boot .test .autoconfigure .jdbc .TestDatabaseAutoConfiguration .EmbeddedDataSourceFactoryBean ;
2425import org .springframework .boot .test .context .runner .ApplicationContextRunner ;
2526import org .springframework .context .annotation .Bean ;
2627import org .springframework .context .annotation .Configuration ;
@@ -49,6 +50,7 @@ void replaceWithNoDataSourceAvailable() {
4950 @ Test
5051 void replaceWithUniqueDatabase () {
5152 this .contextRunner .withUserConfiguration (ExistingDataSourceConfiguration .class ).run ((context ) -> {
53+ assertThat (context ).hasSingleBean (EmbeddedDataSourceFactoryBean .class );
5254 DataSource datasource = context .getBean (DataSource .class );
5355 JdbcTemplate jdbcTemplate = new JdbcTemplate (datasource );
5456 jdbcTemplate .execute ("create table example (id int, name varchar);" );
@@ -60,6 +62,13 @@ void replaceWithUniqueDatabase() {
6062 });
6163 }
6264
65+ @ Test
66+ void whenUsingAotGeneratedArtifactsEmbeddedDataSourceFactoryBeanIsNotDefined () {
67+ this .contextRunner .withUserConfiguration (ExistingDataSourceConfiguration .class )
68+ .withSystemProperties ("spring.aot.enabled=true" )
69+ .run ((context ) -> assertThat (context ).doesNotHaveBean (EmbeddedDataSourceFactoryBean .class ));
70+ }
71+
6372 @ Configuration (proxyBeanMethods = false )
6473 static class ExistingDataSourceConfiguration {
6574
You can’t perform that action at this time.
0 commit comments