Spring Boot: Configuration Class is simply ignored and not loaded

user991710 :

I have the following @Configuration class on the classpath of a few of my @SpringBootApplications:

@Configuration
@Import({MainConfig.class, RestConfig.class})
public class ApiConfig {

    @Bean
    @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
    public Client client() throws ExecutionException, InterruptedException {
        return service.create(Client.class);
    }

}

I have two services that use this config (with differently named Client classes).

Service 1 starts correctly and loads this config. I can see during start up that a bean of type ApiConfig was eagerly initialized.

Service 2 starts incorrectly: the above configuration class is simply ignored and not initialized.

The services are started in separate JVMs.

Ther services have nearly identical, very small application.properties files:

spring.application.name=xxx-api
server.port=0
eureka.name=xxx.api
# Only for reading properties from a central location
context.initializer.classes=com.package.contextClass

I'm not even sure what kind of additional information I could write into the question. I have been going through logs for a couple of hours now and see no discernible difference, simply that it plainly ignores my @Configuration class.

Has anyone had this issue before?

Tom :

The @SpringBootApplication annotation (or, more precisely the inferred @ComponentScan annotation) by default only scans the classpath next to and below the annotated class.

So, your configuration class must be placed next to or in a sub package of you Application class.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=449040&siteId=1