SpringBoot ComponentScan issue with multi-module project

After enabling debug log level for spring and going through extensive logs I found that scanning for various components like JPA Repositories, JPA Entities etc are depending on the Application.java’s package name.

If the JPA Repositories or Entities are not in sub packages of Application.java‘s package then we need to specify them explicitly as follows:

@Configuration
@ComponentScan(basePackages="com.sivalabs.jcart")
@EnableAutoConfiguration
@EnableJpaRepositories(basePackages="com.sivalabs.jcart")
@EntityScan(basePackages="com.sivalabs.jcart")
public class Application{

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

With the above additional @EnableJpaRepositories, @EntityScan I am able to run it using Run As -> Java Application.

But still not sure how it is working fine when Run As -> Spring Boot App!!

Anyway I think it is better to move my Application.java to com.myapp package rather than fighting with SpringBoot!

Leave a Comment