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

ConfigurationClassBeanDefinitionReader.checkConfigurationClassCandidate ignores the metadataReaderFactory argument [SPR-8731] #13373

Closed
spring-projects-issues opened this issue Sep 28, 2011 · 3 comments
Assignees
Labels
in: core

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Sep 28, 2011

Sandu Turcan opened SPR-8731 and commented

I'm trying to use JavaConfig with my own annotations by implementing a MetadataReaderFactory, which translates my annotations into standard Spring.
Unfortunately the metadataReaderFactory argument gets ignored by checkConfigurationClassCandidate:

if (beanDef instanceof AbstractBeanDefinition && ((AbstractBeanDefinition) beanDef).hasBeanClass()) {
    metadata = new StandardAnnotationMetadata(((AbstractBeanDefinition) beanDef).getBeanClass());
}

It seems to be an optimization to avoid unnecessary class lookups but it only works when the metadataReaderFactory creates instances of StandardMetadata.

In 3.1 the code moved to
ConfigurationClassUtils.checkConfigurationClassCandidate


Affects: 3.0.6

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Sep 28, 2011

Chris Beams commented

Hi Sandu,

This sounds like a reasonable request. However, there may be additional changes necessary to support the kind of low-level customization you're attempting here. Since you're already pretty familiar with the changes necessary, I would suggest that you fork the framework on GitHub (http://github.com/cbeams/spring-framework) and try such a change yourself. If it's all you need, great -- if you need more, you can make changes as you go to accommodate.

Once you have stable support for your use case, you can then issue a pull request (along with test cases) and we can discuss it's viability as a general-purpose improvement to the framework.

By the way, you'll find everything you need to build the framework in the wiki attached to the GitHub project.

Cheers,

Chris

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Sep 29, 2011

Sandu Turcan commented

You're right this wasn't the only place.
The other one is:

// ConfigurationClassBeanDefinitionReader.ConfigurationClassBeanDefinition
@Override
public boolean isFactoryMethod(Method candidate) {
    return (super.isFactoryMethod(candidate) && AnnotationUtils.findAnnotation(candidate, Bean.class) != null);
}

I so far managed to make it work by tweaking the beanfactory right before handing it over to ConfigurationClassPostProcessor. Solving it properly may be more involved.
Thanks for the github link I may give it a shot.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Sep 29, 2011

Chris Beams commented

Thanks, Sandu. I'll wait to hear back regarding your experiments.

@spring-projects-issues spring-projects-issues added type: enhancement in: core labels Jan 11, 2019
@spring-projects-issues spring-projects-issues removed the type: enhancement label Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core
Projects
None yet
Development

No branches or pull requests

2 participants