-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Allow custom ClassPathBeanDefinitionScanner on AnnotationConfigServletWebServerApplicationContext #29294
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
Comments
Have you considered registering a custom If that does not work for you, what is the exact use case you have for wanting to override |
I want to make a bean override function. If there is a bean annotated with |
protected boolean checkCandidate(String beanName, BeanDefinition beanDefinition) throws IllegalStateException {
if (!this.registry.containsBeanDefinition(beanName)) {
return true;
}
BeanDefinition existingDef = this.registry.getBeanDefinition(beanName);
BeanDefinition originatingDef = existingDef.getOriginatingBeanDefinition();
if (originatingDef != null) {
existingDef = originatingDef;
}
ReplaceBean replaceAnnotation = replaceBeanAnnotation(beanDefinition.getBeanClassName());
if (replaceAnnotation != null) {
ReplaceBean existAnnotation = replaceBeanAnnotation(existingDef.getBeanClassName());
if (existAnnotation == null || replaceAnnotation.priority() > existAnnotation.priority()) {
this.registry.removeBeanDefinition(beanName);
this.registry.registerBeanDefinition(beanName, beanDefinition);
return true;
} else {
return false;
}
}
if (isCompatible(beanDefinition, existingDef)) {
return false;
}
throw new ConflictingBeanDefinitionException("Annotation-specified bean name '" + beanName +
"' for bean class [" + beanDefinition.getBeanClassName() + "] conflicts with existing, " +
"non-compatible bean definition of same name and class [" + existingDef.getBeanClassName() + "]");
} |
Unless I'm overlooking something, In light of that, I think the Spring Boot team should investigate the possible options here. /cc @philwebb & @wilkinsona |
I don't think it's possible at the moment. We could consider a I'll ask someone to transfer this to Boot. |
We're cleaning out the issue tracker and closing issues that we've not seen much demand to fix. Feel free to comment with additional justifications if you feel that this one should not have been closed. |
I use spring boot 2.5.2 to create a servlet web application, but I cannot find a way to override
ClassPathBeanDefinitionScanner.checkCandidate()
to resolve bean conflicts.This issue is somewhat similar to spring-projects/spring-framework#13962.
The text was updated successfully, but these errors were encountered: