Skip to content

Consistent autowiring behavior for specifically typed injection points against loosely typed @Bean methods [SPR-14960] #19527

Closed
@spring-projects-issues

Description

@spring-projects-issues

satish surabhi opened SPR-14960 and commented

I want to report somewhat similar issue reported here: #15673 , now we are noticing autowire failing intermittently at least on the versions I have tried : 3.2.14 and 4.1.7.RELEASE. Following are the test classes with unit test. The test fails with NoSuchBeanDefinitionException for at least 2 (random) out of 5 attempts.

public interface BarInterface {}

public class Bar implements BarInterface {}

public class Foo {
 @Autowired
 public Bar bar;
}

@Configuration
public class FooBarConfiguration {
    @Bean
    public Foo foo() {
        return new Foo();
    }
    @Bean
    public BarInterface bar() {
        return new Bar();
    }
}

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {FooBarConfiguration.class}, loader=AnnotationConfigContextLoader.class)
public class TestSpringConfiguration {

    @Test
    public void testSpringConfiguration() {
        System.out.println("config test");
    }
}

Reference URL: #15673

Issue Links:

Referenced from: commits 845dbf0, 66aeeed

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions