Skip to content

Behaviour of field injection for List dependencies that are produced and consumed by the same configuration class has changed in 4.3.5 snapshots [SPR-14996] #19563

Closed
@spring-projects-issues

Description

@spring-projects-issues

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

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: regressionA bug that is also a regression

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions