0
votes

My @SpringBootApplication annotation is present in com.abc.def package.

According to this article , using @SpringBootApplication annotation is equivalent to using @Configuration, @EnableAutoConfiguration, and @ComponentScan with their default attributes :-

https://docs.spring.io/spring-boot/docs/2.0.x/reference/html/using-boot-using-springbootapplication-annotation.html

If i supply my own @ComponentScan, does it add new packages to the default value or completely override the default ?

2
but this is trivial to find out, isn't it? - Eugene
I guess it adds to the default, but i need to be doubly sure - user1354825
My Junit tests start failing when i add ComponentScan in app class.( despite being in the same package ) - user1354825

2 Answers

0
votes

@SpringBootApplication annotation can component scan classes from packages under Application class belong to . Also you can add @ComponentScan to scan classes not under package Application class belongs to.

@ComponentScan("external.pkg")
@SpringBootApplication
class MyApp{
}
0
votes

the annotation @SpringBootApplication contains @EnableAutoConfiguration annotation, which will scan through your jar, class, and maven dependencies in the classpath to register beans. If you declare beans cross packages and only want to use specific beans from specific packages, then use @ComponentScan

@ComponentScan gives you a fine-grained package or class level control on what beans you declared would be registered.