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:
Referenced from: commits 547b963, 4571975
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:
It will run successfully with 4.3.4.RELEASE and fail with 4.3.5.BUILD-SNAPSHOT due to
thingsbeingnull.It also works without
required=falsewith 4.3.4.RELEASE but fails with aNoSuchBeanDefinitionExceptionwith 4.3.5.BUILD-SNAPSHOT.It works with both 4.3.4.RELEASE and 4.3.5.BUILD-SNAPSHOT if the field is
Thingrather thanList<Thing>.Affects: 4.3.5
Issue Links:
Referenced from: commits 547b963, 4571975