spring-bootcomponent-scan

Exclude @SpringBootApplication from component scanning


I have two classes marked as @SpringBootApplication under one directory:

@SpringBootApplication
public class FirstSpringBootApplication 

and

@SpringBootApplication
public class SecondSpringBootApplication

@SpringBootApplication annotation contains @ComponentScan annotation and @EnableAutoConfiguration annotation. So, each of two of these classes will consider another as @Configuration bean. How to exclude FirstSpringBoodApplication from component scanning by SecondSpringBootApplication without using profiles?


Solution

  • In case you need to define two or more excludeFilters criteria, you have to use the array.

    For instances in this section of code I want to exclude all the classes in the org.xxx.yyy package and another specific class, MyClassToExclude