Skip to content
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

Add consistent scope support ConfigurationProperties beans #42073

Closed
wants to merge 1 commit into from

Conversation

nosan
Copy link
Contributor

@nosan nosan commented Aug 31, 2024

Added support @Scope for @ConfigurationProperties beans.

To use AnnotationScopeMetadataResolver I had to use AnnotatedGenericBeanDefinition.

Also, I added several tests to verify definition configurations.

gh-41668

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 31, 2024
@nosan
Copy link
Contributor Author

nosan commented Aug 31, 2024

If RootBeanDefinition cannot be changed for some reason, ScopeMetadata can be obtained by

ScopeMetadata metadata = scopeMetadataResolver.resolveScopeMetadata(new AnnotatedGenericBeanDefinition(type));

Or

private ScopeMetadata getScopeMetadata(Class<?> type) {
    ScopeMetadata metadata = new ScopeMetadata();
    MergedAnnotation<Scope> annotation = MergedAnnotations.from(type, SearchStrategy.TYPE_HIERARCHY).get(Scope.class);
    if (annotation.isPresent()) {
        metadata.setScopeName(annotation.getString("value"));
        ScopedProxyMode proxyMode = annotation.getEnum("proxyMode", ScopedProxyMode.class);
        if (proxyMode == ScopedProxyMode.DEFAULT) {
            proxyMode = ScopedProxyMode.NO;
        }
        metadata.setScopedProxyMode(proxyMode);
    }
    return metadata;
}

@nosan nosan force-pushed the gh-41668 branch 2 times, most recently from 11c143b to 116be62 Compare September 1, 2024 08:33
@philwebb philwebb added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 3, 2024
@philwebb philwebb added this to the 3.4.x milestone Sep 3, 2024
@nosan nosan force-pushed the gh-41668 branch 3 times, most recently from 232313b to f950016 Compare September 5, 2024 17:44
@snicoll snicoll self-assigned this Sep 10, 2024
@snicoll snicoll changed the title Support @Scope for @ConfigurationProperties beans Add consistent scope support ConfigurationProperties beans Sep 10, 2024
@snicoll snicoll modified the milestones: 3.4.x, 3.4.0-M3 Sep 10, 2024
@snicoll snicoll closed this in af850a8 Sep 11, 2024
@snicoll
Copy link
Member

snicoll commented Sep 11, 2024

Good stuff @nosan, thanks again! Yeah, I think it makes sense to move to AnnotatedGenericBeanDefinition given the requirement here. I did that in 23d76a0

@nosan nosan deleted the gh-41668 branch September 11, 2024 07:10
@nosan
Copy link
Contributor Author

nosan commented Sep 11, 2024

Thanks @snicoll,

I'm not sure if you've had a chance to see my message on Gitter. If you haven't yet, could you please take a look? I'd appreciate hearing your thoughts on the proposed changes. Apologies for tagging you here, and thanks in advance!

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

Successfully merging this pull request may close these issues.

4 participants