I am trying to create a new starter. I have a business module, for example ProjectManager, which contains some classes annotated with @Component. After the tutorial, I created an autoconfiguration module, it contains an AutoConfiguration class. First, I tried using @ComponentSan to find beans in my business module.
@ComponentScan(value = {"com.foo.project"}) @ConditionalOnClass({Project.class}) @Configuration public class ProjectAutoConfiguration { .... }
But that will not work. I have to add an additional configuration class as shown below:
@Configuration @ComponentScan(value = {"com.foo.project"}) @MapperScan(value = {"com.foo.project"}) public class ProjectConfig { }
And then import it into the AutoConfiguration class, as shown below:
@Import(ProjectConfig.class) @ConditionalOnClass({Project.class}) @Configuration public class ProjectAutoConfiguration { .... }
It works. But according to spring doc .
automatic configuration is implemented with standard @Configuration classes
So my question is: why is @ComponentScan not working here? Did I do something wrong? Or is it design?
source share