I have a Spring boot application and I want to import a dependency written in spring boot that defines some controllers.
Maybe it is straightforward, but how can I made the main application able to initialize all these controllers in the imported module? When I try to access the path to these controllers I get a error for missing handler method for the given path. I tried as follows:
@SpringBootApplication
@ComponentScan(basePackages = {"com.main.project", "com.imported.dependency"})
public class MyApplication
implements CommandLineRunner {
public static void main(final String... args) {
SpringApplication app = new SpringApplication(MyApplication.class);
app.setWebEnvironment(true);
app.run(args);
}
}
i.e. I tried with @ComponentScan
, but nothing happens.
I also tried to see if the controllers are loaded:
ApplicationContext ctx = SpringApplication.run(FrontendApplication.class, args);
System.out.println("Let's inspect the beans provided by Spring Boot:");
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}
They are not. I tried to remove @SpringBootApplication
and to use @EnableAutoConfiguration
and @ComponentScan
, but this does not work.
Suggestions?
The Model Module contains Entities and Visual Objects to be used in the project. The Repository module contains repositories to be used in the project. It depends on the Model Module. The Service API module contains all project services.
In Spring MVC, we can create multiple controllers at a time. It is required to map each controller class with @Controller annotation.
after the discussion on the main thread I tried to setup a small project that's like yours and I put it on github, I can't see any problem.
Give it a look https://github.com/e-ivaldi/mat_boy_test
This is from the log 2015-10-24 17:22:02.900 INFO 31901 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/**]}" onto public java.lang.String com.somethingelse.controllers.SimpleController.xxx()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With