0

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?

Sae1962
  • 1,122
  • 15
  • 31
Serhii Soboliev
  • 820
  • 1
  • 13
  • 21
  • Try to check if this works for you https://stackoverflow.com/questions/18992880/exclude-component-from-componentscan –  Apr 27 '22 at 19:36

2 Answers2

2

The annotate class with below annotations will work similarly as @SpringBootApplication. It also does the same, and the excludeFilter is important, which is used to specify which class not to include while scanning.

@EnableAutoConfiguration
@ComponentScan(excludeFilters={@Filter(type=CUSTOM, classes={TypeExcludeFilter.class})})
Sae1962
  • 1,122
  • 15
  • 31
rajadilipkolli
  • 3,475
  • 2
  • 26
  • 49
0

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