Skip to content

Exclude infrastructure beans from lazy init early #46755

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

Conversation

hojooo
Copy link

@hojooo hojooo commented Aug 10, 2025

ROLE_INFRASTRUCTURE bean added early return logic prior to bean type interpretation(getType) to be excluded from lazy-init in any case.
I think this code can eliminate the possibility that Infrastructure bean will accidentally turn into Lazy-init=true, even if beanType is null or type inference is limited.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 10, 2025
@snicoll
Copy link
Member

snicoll commented Aug 10, 2025

@hojooo thanks for the PR but we can't make this change without an actionable issue. Please provide that and then we can see if we want to make this change.

@snicoll snicoll added the status: waiting-for-feedback We need additional information before we can continue label Aug 10, 2025
@hojooo
Copy link
Author

hojooo commented Aug 10, 2025

@snicoll Thanks for the feedback!

I think getBeanType() can return null in the following situation.

@Component  
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public class InfrastructureBean implements FactoryBean<Object> {
    
    @Override
    public Object getObject() {
        return new SomeInfrastructureComponent();
    }
    
    @Override
    public Class<?> getObjectType() {
        return null;  // FactoryBean allows null
    }
}

Spring's own FactoryBean contract allows null, and this change ensures infrastructure beans remain protected even in these edge cases. Is this too unusual? I thought it was better to exclude it more explicitly. Thank you!

@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 Aug 10, 2025
@snicoll
Copy link
Member

snicoll commented Aug 11, 2025

Thanks for following up.

Spring's own FactoryBean contract allows null,

Yes, I am aware of that. and isExcluded that is called here does account for the fact that beanType may be null. If that's what you were trying to protect against, then the code as we have is fine.

@snicoll snicoll closed this Aug 11, 2025
@snicoll snicoll added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided labels Aug 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants