Skip to content
This repository was archived by the owner on Jan 19, 2022. It is now read-only.

@ConditionalOnAwsCloudEnvironment at method level #389

Closed
bsamartins opened this issue Nov 15, 2018 · 4 comments
Closed

@ConditionalOnAwsCloudEnvironment at method level #389

bsamartins opened this issue Nov 15, 2018 · 4 comments
Labels
component: core An issue related to core functionality - credentials, region resolution help wanted type: bug A general bug
Milestone

Comments

@bsamartins
Copy link
Contributor

When setting @ConditionalOnAwsCloudEnvironment or @ConditionalOnMissingAwsCloudEnvironment (Srping Cloud 2.0.0) at a method level i would have expected the bean to be created on the environment that matches the condition, but instead it's ignored. It works fine at class level.

The below example will produce two beans with value "cloud" and "local" regardless of the environment.

@Configuration
class MyConfig {
   
    @ConditionalOnAwsCloudEnvironment 
    public String cloud() {
        return "cloud"
    }

    @ConditionalOnMissingAwsCloudEnvironment 
    public String local() {
        return "local"
    }

}

Could it be related with the ConfigurationPhase?
https://github.com/spring-cloud/spring-cloud-aws/blob/3bfd3a537192cf38a14c7a0c8df16876511db42a/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/annotation/OnAwsCloudEnvironmentCondition.java#L30-L33

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 15, 2018
@spencergibb spencergibb removed the status: waiting-for-triage An issue we've not yet triaged label Nov 19, 2018
@spencergibb
Copy link
Contributor

Not sure. Do you want to experiment and try changing the phase and see if that help? That condition hits an aws endpoint, so that may have something to do with it as well.

@spencergibb spencergibb added the status: waiting-for-feedback We need additional information before we can continue label Nov 19, 2018
@bsamartins
Copy link
Contributor Author

https://github.com/spring-projects/spring-framework/blob/master/spring-context/src/main/java/org/springframework/context/annotation/ConditionEvaluator.java#L103-L113

I was debugging the code and it never got to evaluate if the condition matched (at a method level), because the phase was REGISTER_BEAN and the requiredPhase was PARSE_CONFIGURATION.

Returning null or ConfigurationPhase.REGISTER_BEAN on the getConfigurationPhase seams to make it work just fine.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Nov 26, 2018
@jonfreedman
Copy link

It does appear that beans which are annotated @ConditionalOnMissingAwsCloudEnvironment are created on AWS which is unfortunate - either this should be fixed, or the ElementType.METHOD target should be removed.

@spencergibb spencergibb added type: bug A general bug help wanted and removed status: feedback-provided Feedback has been provided labels Jan 31, 2019
@spencergibb
Copy link
Contributor

PRs welcome

@maciejwalkowiak maciejwalkowiak added this to the 2.2.3 milestone May 30, 2020
@maciejwalkowiak maciejwalkowiak added the component: core An issue related to core functionality - credentials, region resolution label May 31, 2020
maciejwalkowiak pushed a commit to maciejwalkowiak/spring-cloud-aws that referenced this issue May 31, 2020
maciejwalkowiak pushed a commit to maciejwalkowiak/spring-cloud-aws that referenced this issue Oct 15, 2020
maciejwalkowiak pushed a commit to maciejwalkowiak/spring-cloud-aws that referenced this issue Oct 15, 2020
maciejwalkowiak pushed a commit to maciejwalkowiak/spring-cloud-aws that referenced this issue Oct 15, 2020
maciejwalkowiak pushed a commit to maciejwalkowiak/spring-cloud-aws that referenced this issue Oct 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
component: core An issue related to core functionality - credentials, region resolution help wanted type: bug A general bug
Development

No branches or pull requests

5 participants