Eddie Martinez
Eddie Martinez

Reputation: 13910

springboot How to exclude configuration class in dependency dependency

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

Upvotes: 10

Views: 19115

Answers (1)

stacker
stacker

Reputation: 4475

you can use @ComponentScan to exclude classes:

@ComponentScan(basePackages = {"package1","package2"},
  excludeFilters = {@ComponentScan.Filter(
    type = FilterType.ASSIGNABLE_TYPE,
    value = {ExcludedConfigClass.class})
  })

Upvotes: 11

Related Questions