-
Notifications
You must be signed in to change notification settings - Fork 40.8k
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
Profiles are not active when the environment is prepared with an AOT-optimized application #41562
Comments
It is to be expected that the
The profile's set in the initialiser that's generated by Spring Framework. For your client application, that initialiser looks like this: @Generated
public class ConfigClientApplication__ApplicationContextInitializer implements ApplicationContextInitializer<GenericApplicationContext> {
@Override
public void initialize(GenericApplicationContext applicationContext) {
DefaultListableBeanFactory beanFactory = applicationContext.getDefaultListableBeanFactory();
beanFactory.setAutowireCandidateResolver(new ContextAnnotationAutowireCandidateResolver());
beanFactory.setDependencyComparator(AnnotationAwareOrderComparator.INSTANCE);
applicationContext.getEnvironment().addActiveProfile("native_runtime");
addImportAwareBeanPostProcessors(beanFactory);
new ConfigClientApplication__BeanFactoryRegistrations().registerBeanDefinitions(beanFactory);
new ConfigClientApplication__BeanFactoryRegistrations().registerAliases(beanFactory);
}
/**
* Add ImportAwareBeanPostProcessor to support ImportAware beans.
*/
private void addImportAwareBeanPostProcessors(DefaultListableBeanFactory beanFactory) {
Map<String, String> mappings = new HashMap<>();
mappings.put("org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration", "org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration$EnableTransactionManagementConfiguration$CglibAutoProxyConfiguration");
RootBeanDefinition beanDefinition = new RootBeanDefinition(ImportAwareAotBeanPostProcessor.class);
beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
beanDefinition.setInstanceSupplier(() -> new ImportAwareAotBeanPostProcessor(mappings));
beanFactory.registerBeanDefinition("org.springframework.context.annotation.internalImportAwareAotProcessor", beanDefinition);
}
} The call to add |
Hey @wilkinsona - thanks a lot for the fast feedback. It would be great to see this fix soon as we need to adjust our build / runtime environment to add an additional profile which overrides the properties set by the aot-process. Example:
This way you can easily see that the build profile is merged with the runtime profile. The load hierarchy would be Can you label this ticket correspondingly? |
Can you explain why there's some urgency for a fix? If we do something here, I think it will be to ensure that |
The issue is not to fully enable Because of aot-process I guess there is no way to change the profile order, is there?
|
Just specify the active profiles as they should be loaded as Andy already explained. The AOT processed code will enable the profile only if it hasn't been enabled previously. |
So basically this way: If yes there is indeed no urgency. 👍 |
Hey @snicoll and @wilkinsona - again thanks a lot for the help! 🎉 As mentioned in the comment: #41562 (comment) - just to summarize: We are going to separate the YML file into 3 profiles:
Changes: klopfdreh/native-cloud-config-test@38c9379 To run the image we are going to use: |
Thanks a lot for fixing this. 👍 |
I am not sure whether to file the issue here or to Spring Cloud Config directly because I don't know at which part the issue occurs.
I want to port an application to Spring Boot Native with Spring Cloud Config. We followed the documentation of
Spring Boot Native here: https://docs.spring.io/spring-boot/reference/packaging/native-image/index.html and
Spring Cloud Config Native here: https://docs.spring.io/spring-cloud-config/docs/current/reference/html/#_aot_and_native_image_support_2
I created a repository to demonstrate the issue: https://github.com/klopfdreh/native-cloud-config-test and provided 9 steps in the README.md to reproduce it.
Short summary: Spring AOT processes the application with the profile
native_runtime
which the running application logs as active on startup. From the config server how ever the definition of the profile is not fetched - onlydefault
.What we wanted is that the native image is running with no profile active and only the
default
configuration is used.The logging that a profile is active and not fetched from the config server is somehow confusing.
Comparison:
Java Application with
native_runtime
profile activated:Native Application:
Native Application with env var
SPRING_PROFILES_ACTIVE=native_runtime
activated:The text was updated successfully, but these errors were encountered: