Skip to content

@Autowired List<ToAutoWire> into Configuration that defines @Bean ToAutoWire fails [SPR-12646] #17247

Closed
@spring-projects-issues

Description

@spring-projects-issues

Rob Winch opened SPR-12646 and commented

Starting with Spring 4.0.7 (4.0.6 works) the following setup will fail because only the ToAutoWire("a") will be Autowired :

public class ToAutoWire {
    private final String name;

    public ToAutoWire(String name) {
        super();
        this.name = name;
    }
}

@Configuration
public class ConfigA {

    @Bean
    public ToAutoWire a() {
        return new ToAutoWire("a");
    }
}

@Configuration
public class ConfigB {
    List<ToAutoWire> values;

    @Bean
    public ToAutoWire b() {
        return new ToAutoWire("b");
    }

    @Autowired
    public void setValues(List<ToAutoWire> values) {
        this.values = values;
    }
}

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {ConfigA.class, ConfigB.class})
public class AutowireListTests {
    @Autowired
    ConfigB b;

    @Test
    public void run() {
        assertEquals(2,b.values.size());
    }
}

A few notes:


Affects: 4.0.7, 4.0.8, 4.0.9, 4.1 GA, 4.1.1, 4.1.2, 4.1.3, 4.1.4

Reference URL: https://github.com/rwinch/spring-framework-issues/tree/SPR-12646

Issue Links:

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: declinedA suggestion or change that we don't feel we should currently apply

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions