I am using a library dependency which contains a @configuration
class that I need to be ignored.
When I do
@SpringBootApplication(exclude={NeedsToBeExcluded.class})
public class Startup {
public static void main(String[] args) {
SpringApplication.run(Startup.class, args);
}
I get the Exception
nested exception is java.lang.IllegalStateException: The following classes could not be excluded because they are not auto-configuration classes: NeedsToBeExcluded.class
If the class is not on the classpath, you can use the excludeName attribute of the annotation and specify the fully qualified name instead. Finally, you can also control the list of auto-configuration classes to exclude by using the spring. autoconfigure. exclude property.
If you find that specific auto-configure classes are being applied that you don't want, you can use the exclude attribute of @EnableAutoConfiguration to disable them. If the class is not on the classpath, you can use the excludeName attribute of the annotation and specify the fully qualified name instead.
exclude , not excludes as in the release notes. This helps prevent Spring Boot from loading autoconfig classes in the presence of multiple @EnableAutoConfiguration / @SpringBootApplication annotations.
How They Differ. The main difference between these annotations is that @ComponentScan scans for Spring components while @EnableAutoConfiguration is used for auto-configuring beans present in the classpath in Spring Boot applications.
you can use @ComponentScan to exclude classes:
@ComponentScan(basePackages = {"package1","package2"},
excludeFilters = {@ComponentScan.Filter(
type = FilterType.ASSIGNABLE_TYPE,
value = {ExcludedConfigClass.class})
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With