Skip to content

spring-cloud-starter-bootstrap dependency breaks ApplicationContextInitializer usage #893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sergey-morenets opened this issue Jan 28, 2021 · 3 comments
Labels

Comments

@sergey-morenets
Copy link

Hi

I have a project that uses Spring Cloud Config Consul. I can't use spring.config.import property (because it doesn't support Spring Retry now). You can view details here: https://github.com/spring-cloud/spring-cloud-consul/issues/703
So I added spring-cloud-starter-bootstrap dependency and it helped if I don't use custom ApplicationContextInitializer.

For example, here's my simplified project:

@SpringBootApplication
@EnableConfigurationProperties(UserProperties.class)
public class ConsulClientApplication {
	public static void main(String[] args) {
		SpringApplication.run(ConsulClientApplication.class, args);
	}
}

@ConfigurationProperties 
public class UserProperties {}

public class ConsulData {
	
	private final UserProperties userProperties;

	public ConsulData(UserProperties userProperties) {
		this.userProperties = userProperties;
	}
}

public class GatewayContextInitializer implements ApplicationContextInitializer<GenericApplicationContext> {

	@Override
	public void initialize(GenericApplicationContext ctx) {
		ctx.registerBean(ConsulData.class);
	}
}

And my META-INF/spring.factories:

org.springframework.context.ApplicationContextInitializer=demo.GatewayContextInitializer

Without spring-cloud-starter-bootstrap dependency my application starts properly. If I add this dependency then I get an exception:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'demo.UserProperties' available: expected at least 1 bean which qualifies as autowire candidate.

Please, advise how to resolve this issue.

@spencergibb
Copy link
Member

I'm afraid this was precisely one of the reasons we made spring.config.import the default. I'm afraid there's no fix or workaround.

@sergey-morenets
Copy link
Author

I'm afraid this was precisely one of the reasons we made spring.config.import the default. I'm afraid there's no fix or workaround.

Ok, then do you plan to integrate Spring Retry and Spring Config import in Cloud Consul? If so then can you please provide estimates?
I saw that you already provided similar fix for Spring Cloud Config Server.

@spencergibb
Copy link
Member

It will be in the next release. I can't give a better estimate than weeks, but not months.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants