Closed
Description
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:
- Unable to autowire concrete classes when java config methods return interface [SPR-11046] #15673 Unable to autowire concrete classes when java config methods return interface
- Non-helpful NoSuchBeanDefinitionException rather than BeanNotOfRequiredTypeException due to creation order [SPR-14504] #19073 Non-helpful NoSuchBeanDefinitionException rather than BeanNotOfRequiredTypeException due to creation order
- Deterministic and JVM-independent @Bean registration order within Class-reflected configuration classes [SPR-14505] #19074 Deterministic and JVM-independent
@Bean
registration order within Class-reflected configuration classes