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

Dependency injection matches wildcards too leniently with 6.2.1 #34119

Open
kse-music opened this issue Dec 19, 2024 · 0 comments
Open

Dependency injection matches wildcards too leniently with 6.2.1 #34119

kse-music opened this issue Dec 19, 2024 · 0 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: regression A bug that is also a regression
Milestone

Comments

@kse-music
Copy link

kse-music commented Dec 19, 2024

Steps to reproduce:

  1. Define two interfaces ObjectPostProcessor and AuthorizationManager
public interface ObjectPostProcessor<T> {

    void process(T t);

}

public interface AuthorizationManager<T> {

    T getValue();

}
  1. SimpleStart as config class
public class SimpleStart implements ApplicationContextAware {

    @Bean
    static ObjectPostProcessor<Object> objectObjectPostProcessor(){
        return o -> {

        };
    }

    @Bean
    static ObjectPostProcessor<AuthorizationManager<?>> authorizationManagerPostProcessor(){
        return o -> {

        };
    }

  @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        ResolvableType type = ResolvableType.forClassWithGenerics(ObjectPostProcessor.class, Object.class);
        ObjectProvider<ObjectPostProcessor<Object>> postProcessors = applicationContext.getBeanProvider(type);
        ObjectPostProcessor<Object> object = postProcessors.getObject();
        System.out.println(object);
    }

}

  1. Run
public class SpringTest {
  @Test
    public void research() {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SimpleStart.class);
    }
}
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'simpleStart': No qualifying bean of type 'cn.hiboot.framework.research.spring.research.ObjectPostProcessor<java.lang.Object>' available: expected single matching bean but found 2: objectObjectPostProcessor,authorizationManagerPostProcessor

	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:608)

It does work well when I replaced ? with Object, I wonder if this scene needs to be supported in the future?

In Addition, I found that it was due to the change of #33982. But before that, it was good

Related to SEC#16299

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Dec 19, 2024
@jhoeller jhoeller added type: regression A bug that is also a regression in: core Issues in core modules (aop, beans, core, context, expression) and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Dec 19, 2024
@jhoeller jhoeller self-assigned this Dec 19, 2024
@jhoeller jhoeller added this to the 6.2.2 milestone Dec 19, 2024
@jhoeller jhoeller changed the title Dependency injection does not support wildcards with 6.2.1 Dependency injection matches wildcards too leniently with 6.2.1 Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

3 participants