I have 2 projects, the main spring boot project and the second spring project, which contains @Contollers, @Services and so on.
I try to use some of this services in main project. I saw similar questions like here, here, here and many others, but it does not work for me
1) if I have just
@SpringBootApplication
public class App { ... }
then it does not compile because can not find services from the second project
2) if I try to scan the second package
@SpringBootApplication
@ComponentScan("secondPackage")
public class App {}
then the application starts without errors, but controller mapping does not work at all. Mapping from both projects can not be resolved.
3) then I tried exclude controllers from second package, because I do not need them, mapping still does not work
@ComponentScan(basePackages="secondPackage", excludeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION, value = Controller.class)})
4) then I tried to scan for particular services, but in this case other resources are not available and I have to include to much paths
@ComponentScan({"first package", "second package"})
5) finally I tried to make 2 configuration files
@Configuration
@ComponentScan(basePackages = {"mainPackage"})
public class MainConfiguration {
}
@Configuration
@ComponentScan(basePackages="secondPackage",
excludeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION, value = Controller.class)})
public class SecondConfiguration {
}
but I did not found example, how I can prepare context before SpringApplication.run(App.class, args); and then make the app run with my context. like
ApplicationContext myContext = new AnnotationConfigApplicationContext(OrderStatusConfiguration.class, ShopRuServicesConfiguration.class);
SpringApplication.run(App.class, myContext, args);
So please give me an advice, why mapping does not work or how should I proper autowire services from the second project!
I appreciate any help! Thanks!