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?