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 24
24
import org .apache .commons .logging .Log ;
25
25
import org .apache .commons .logging .LogFactory ;
26
26
27
+ import org .springframework .aot .AotDetector ;
27
28
import org .springframework .beans .BeansException ;
28
29
import org .springframework .beans .factory .FactoryBean ;
29
30
import org .springframework .beans .factory .InitializingBean ;
@@ -83,6 +84,9 @@ static class EmbeddedDataSourceBeanFactoryPostProcessor implements BeanDefinitio
83
84
84
85
@ Override
85
86
public void postProcessBeanDefinitionRegistry (BeanDefinitionRegistry registry ) throws BeansException {
87
+ if (AotDetector .useGeneratedArtifacts ()) {
88
+ return ;
89
+ }
86
90
Assert .isInstanceOf (ConfigurableListableBeanFactory .class , registry ,
87
91
"Test Database Auto-configuration can only be used with a ConfigurableListableBeanFactory" );
88
92
process (registry , (ConfigurableListableBeanFactory ) registry );
Original file line number Diff line number Diff line change 21
21
import org .junit .jupiter .api .Test ;
22
22
23
23
import org .springframework .boot .autoconfigure .AutoConfigurations ;
24
+ import org .springframework .boot .test .autoconfigure .jdbc .TestDatabaseAutoConfiguration .EmbeddedDataSourceFactoryBean ;
24
25
import org .springframework .boot .test .context .runner .ApplicationContextRunner ;
25
26
import org .springframework .context .annotation .Bean ;
26
27
import org .springframework .context .annotation .Configuration ;
@@ -49,6 +50,7 @@ void replaceWithNoDataSourceAvailable() {
49
50
@ Test
50
51
void replaceWithUniqueDatabase () {
51
52
this .contextRunner .withUserConfiguration (ExistingDataSourceConfiguration .class ).run ((context ) -> {
53
+ assertThat (context ).hasSingleBean (EmbeddedDataSourceFactoryBean .class );
52
54
DataSource datasource = context .getBean (DataSource .class );
53
55
JdbcTemplate jdbcTemplate = new JdbcTemplate (datasource );
54
56
jdbcTemplate .execute ("create table example (id int, name varchar);" );
@@ -60,6 +62,13 @@ void replaceWithUniqueDatabase() {
60
62
});
61
63
}
62
64
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
+
63
72
@ Configuration (proxyBeanMethods = false )
64
73
static class ExistingDataSourceConfiguration {
65
74
You can’t perform that action at this time.
0 commit comments