Let’s have such configuration class:
<code>@Configuration
@ImportAutoConfiguration(classes = {DataSourceConfig.class })
public class AppConfig {}
</code>
<code>@Configuration
@ImportAutoConfiguration(classes = {DataSourceConfig.class })
public class AppConfig {}
</code>
@Configuration
@ImportAutoConfiguration(classes = {DataSourceConfig.class })
public class AppConfig {}
And some test:
<code>@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK)
public class SecurityIntegrationTest {}
</code>
<code>@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK)
public class SecurityIntegrationTest {}
</code>
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK)
public class SecurityIntegrationTest {}
When I run the test, the beans introduced in @ImportAutoConfiguration
are being executed, which is not an intended behaviour and the test fail.
I tried to annotate the test with:
<code>@ComponentScan(excludeFilters={@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = DataSourceConfig.class)})
</code>
<code>@ComponentScan(excludeFilters={@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = DataSourceConfig.class)})
</code>
@ComponentScan(excludeFilters={@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = DataSourceConfig.class)})
but it had no effect. I tried to provide a test configuration:
<code>@TestConfiguration
@EnableAutoConfiguration(exclude = { DataSourceConfig.class })
public class LocalTestConfiguration {}
</code>
<code>@TestConfiguration
@EnableAutoConfiguration(exclude = { DataSourceConfig.class })
public class LocalTestConfiguration {}
</code>
@TestConfiguration
@EnableAutoConfiguration(exclude = { DataSourceConfig.class })
public class LocalTestConfiguration {}
but it fails too:
<code>java.lang.IllegalStateException: The following classes could not be excluded because they are not auto-configuration classes: DataSourceConfig
</code>
<code>java.lang.IllegalStateException: The following classes could not be excluded because they are not auto-configuration classes: DataSourceConfig
</code>
java.lang.IllegalStateException: The following classes could not be excluded because they are not auto-configuration classes: DataSourceConfig
So what’s the approach to take in Spring boot 2.7 to avoid Spring to load the classes mentioned in AppConfig
?