r/learnjava•
emmg90

[Spring-Boot] Why use @ComponentScan to scan for classes in a local library located in Maven Dependencies

Hi, I am trying to figure out why do I have to use @ComponentScan to autowire classes located in a JAR that I made and installed locally on my repo but I don't use that way with every library located in Maven Dependencies (I know @SpringBootApplication includes @ComponentScan as well).

Also, one more way was to move main method one level up so my library is at com.example.AFunctionality and main is at com.example but what will happen if my library was at com.test.AFunctionality?

So why my library requires special care?

Posted Apr 24, 2018, 7:59 PM UTC

42
nutrecht•

There's a difference between code being available to use (putting it on your classpath) and Spring being told to find and create instances of the components (componentscanning).

1
[deleted]•

[removed]

1