Autwired Spring Beans via Java Packages

I am trying to split my project into three modules: core, admin and user, so that I can share common code through the kernel. The problem is that I cannot get Spring to pick up autolevel beans in different main packages, when I have everything in the same package in which it works.

In the com.mickeycorp.core package, I have models, services, etc. that I want to use to use the admin and user modules. In com.mickeycorp.admin, this is my WebApplicationStarter (extends SpringBootServletInitializer), where Ive got:

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(SpringConfiguration.class);
    return application.sources(WebApplicationStarter.class);
}

Which, I believe, should pick up my configuration class, where I have the following:

@Configuration
@ComponentScan("com.mickeycorp")
public class SpringConfiguration {

}

It is clear that I did not understand something. I thought installing ComponentScan would guide Spring through packages in com.mickeycorp for component annotations?

+4
2

.. @ComponentScan , , Spring - @Component @Repository, @Service @Controller. : @Entity @Repository:

@EntityScan("com.mickeycorp.core")
@EnableJpaRepositories("com.mickeycorp.core")

SpringApplicationBuilder , SpringConfiguration .

:

Spring :

Spring : EnableJpaRepositories

+3

@ComponentScan .

, Spring ,

basePackageClasses(), basePackages() ( value()).

@ComponentScan(basePackages={"package1","package2"})
0

All Articles