Closed
Description
Andy Wilkinson opened SPR-14996 and commented
I noticed this in 5.0 as well but didn't think too much of it, however I've just noticed that the latest 4.3.5 snapshots exhibit the same change in behaviour.
Here's small application that will reproduce the problem:
package com.example;
import java.util.List;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.Assert;
public class FieldInjectionBehaviorChange {
public static void main(String[] args) {
new AnnotationConfigApplicationContext(ExampleConfiguration.class).close();
}
@Configuration
static class ExampleConfiguration {
@Autowired(required = false)
private List<Thing> things;
@PostConstruct
public void postConstruct() {
Assert.notNull(this.things);
}
@Bean
public Thing thing() {
return new Thing() {};
}
}
interface Thing {
}
}
It will run successfully with 4.3.4.RELEASE and fail with 4.3.5.BUILD-SNAPSHOT due to things
being null
.
It also works without required=false
with 4.3.4.RELEASE but fails with a NoSuchBeanDefinitionException
with 4.3.5.BUILD-SNAPSHOT.
It works with both 4.3.4.RELEASE and 4.3.5.BUILD-SNAPSHOT if the field is Thing
rather than List<Thing>
.
Affects: 4.3.5
Issue Links:
- Self reference fallback in 4.3 is not meant to apply to collection elements [SPR-14965] #19532 Self reference fallback in 4.3 is not meant to apply to collection elements
- Modification in AbstractAutowireCapableBeanFactory to prevent stackoverflow errors causes context not to load. [SPR-15125] #19692 Modification in AbstractAutowireCapableBeanFactory to prevent stackoverflow errors causes context not to load.