Skip to content

Make spring support like CDI @Produces (for Array/Map/Collection inject) [SPR-11269] #15894

Closed

Description

@spring-projects-issues

zhangkaitao opened SPR-11269 and commented

cdi support like

 
@Produces
List<Conference> availableConfs;

see http://my.oschina.net/hantsy/blog/186939

because spring implement array/collection/map inject use find Component bean then add to array/collection/map。Can simple modify DefaultListableBeanFactory to support。please see 864 line:
https://github.com/zhangkaitao/spring4-showcase/blob/master/spring4-others/src/test/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java

1、find like List<BeanInterface> bean;
2、find BeanInterface bean,add to List;
3、others;

example:
https://github.com/zhangkaitao/spring4-showcase/blob/master/spring4-others/src/test/java/com/sishuok/spring4/genericinject/GenericInjectTest.java

only support java config way,if want support xml,need modify bean definition(add ResolvableType else collection class)


Affects: 4.0 GA

Issue Links:

Activity

  1. spring-projects-issues commented on Feb 14, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Gaurav Rawat commented

    This will be pretty cool if we can have CDI @produces support specially for injecting methods .

  2. spring-projects-issues commented on Feb 14, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    This is more or less a duplicate of our 4.3 work towards refining our injection matching algorithm. We do it using Spring's common annotation style (@Bean etc), simply allowing to match beans which are collections themselves now. This is functionally equivalent to CDI's @Produces, just bound to factory methods and naturally integrated with all of Spring's other matching options.

    Please give a recent 4.3.0.BUILD-SNAPSHOT a try there. RC1 is coming up in late March.

    Juergen

  3. spring-projects-issues commented on Feb 14, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Gaurav Rawat commented

    OK @bean note works on non configuration classes now great. Let me give it a try . thanks

  4. added
    type: enhancement
    in: core
    status: duplicate
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: corestatus: duplicatetype: enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions