I\'m currently working on a REST API with Spring Boot.
I\'m new to Maven and have just started coding with IDEA (don\'t know well this IDE yet), and I have a problem
You need to tell SpringBoot where to look for your controllers. Per default that only happens in sub-packages of your @SpringBootApplication
class (which will probably not include your sub module).
In order to change that you can use @ComponentScan("path.to.package")
to change the default package.
Additionally, you can use @EntityScan
to do the same for @Entity
classes that might be in your sub-module.
also note that in case of JPA Entities and repositories are not in sub packages of Application.java's package then @Entityscan and @EnableJpaRepositories MUST be declared in the Application class, e.g:
@Configuration
@ComponentScan(basePackages="com.my.pack")
@EnableAutoConfiguration
@EnableJpaRepositories(basePackages="com.my.pack")
@EntityScan(basePackages="com.my.pack")
public class Application{
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Your project structured as:
if your App.java in a package: com.xxxx.pro,then set the sub module's package is com.xxx.pro,such as your sub module's controller is TestController.java, and the code is:
package com.xx.pro.web;
@RestController
public class TestController{
}
so, this sub moudle's TestController will be sanned by App.java.Try it on, good luck.