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

Allow setting custom ClassPathBeanDefinitionScanner on AnnotationConfigWebApplicationContext [SPR-9324] #13962

Closed
spring-projects-issues opened this issue Apr 12, 2012 · 2 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Richard L. Allen opened SPR-9324 and commented

We use a custom ClassPathBeanDefinitionScanner along with AnnotationConfigWebApplicationContext. To achieve this, we have to extend AnnotationConfigWebApplicationContext and override the loadBeanDefinitions method to substitute our custom scanner. Would be nice if AnnotationConfigWebApplicationContext simply had a set method for the scanner the same as the set methods for the BeanNameGenerator and ScopeMetadataResolver.


Affects: 3.1.1

Referenced from: commits 0230c49, 20beace

Backported to: 4.1.9

1 votes, 1 watchers

@spring-projects-issues
Copy link
Collaborator Author

Chris Beams commented

Hi Richard,

I see what you mean - overriding ACWAC#loadBeanDefinitions does represent quite a bit of code duplication.

On the other hand, providing a #setClassPathBeanDefinitionScanner method isn't ideal either. First, it's adding a public method for what is almost certainly a very uncommon use case; second, the scanner requires the BeanFactory at construction time, and this is not yet available.

As a compromise, I would consider a pull request that introduces protected methods with the following signatures:

protected ClassPathBeanDefinitionScanner getClassPathBeanDefinitionScanner(BeanDefinitionRegistry registry);

protected AnnotatedBeanDefinitionReader getAnnotatedBeanDefinitionReader(BeanDefinitionRegistry registry);

The default implementations of these methods would be simply to return new CPBDS(registry) and new ABDR(registry) respectively. But they would also of course allow you to override exactly the methods you need instead of the entirety of #loadBeanDefinitions.

You can find out more about issuing pull requests by reading the contributor guidelines.

Thanks!

@spring-projects-issues
Copy link
Collaborator Author

Val Blant commented

I would really like to see this feature as well!

We need to override the way ClassPathBeanDefinitionScanner resolves beanName conflicts, which is an extremely simple change to the checkCandidate() method, but there is no way to plug in a different Scanner cleanly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants