I have a Spring boot application and I want to import a dependency written to a Spring boot that defines some controllers.
It may be simple, but how can I get the main application to initialize all these controllers in the imported module? When I try to access the path to these controllers, I get an error for the missing handler method for this path. I tried the following:
@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 check if the controllers are loaded:
ApplicationContext ctx = SpringApplication.run(FrontendApplication.class, args); System.out.println("Let inspect the beans provided by Spring Boot:"); String[] beanNames = ctx.getBeanDefinitionNames(); Arrays.sort(beanNames); for (String beanName : beanNames) { System.out.println(beanName); }
This is not true. I tried to remove @SpringBootApplication and use @EnableAutoConfiguration and @ComponentScan , but this will not work.
Suggestions?
source share