spring-projects/spring-framework · error · BeanCreationException

Invalid autowire-marked constructors: {}. Found constructor

Error message

Invalid autowire-marked constructors: {}. Found constructor with 'required' Autowired annotation: {}

What it means

Thrown by determineCandidateConstructors() when a class declares multiple @Autowired constructors and at least one of them is marked required=true (the default). Spring permits multiple @Autowired constructors only if all of them are optional (required=false); at most one constructor may be required. When a second required constructor or any preceding optional candidate already exists and a required one is then encountered, the combination is ambiguous and Spring refuses to pick an injection constructor.

Source

Thrown at spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java:406

											userClass.getDeclaredConstructor(candidate.getParameterTypes());
									ann = findAutowiredAnnotation(superCtor);
								}
								catch (NoSuchMethodException ex) {
									// Simply proceed, no equivalent superclass constructor found...
								}
							}
						}
						if (ann != null) {
							if (requiredConstructor != null) {
								throw new BeanCreationException(beanName,
										"Invalid autowire-marked constructor: " + candidate +
										". Found constructor with 'required' Autowired annotation already: " +
										requiredConstructor);
							}
							boolean required = determineRequiredStatus(ann);
							if (required) {
								if (!candidates.isEmpty()) {
									throw new BeanCreationException(beanName,
											"Invalid autowire-marked constructors: " + candidates +
											". Found constructor with 'required' Autowired annotation: " +
											candidate);
								}
								requiredConstructor = candidate;
							}
							candidates.add(candidate);
						}
						else if (candidate.getParameterCount() == 0) {
							defaultConstructor = candidate;
						}
					}
					if (!candidates.isEmpty()) {
						// Add default constructor to list of optional constructors, as fallback.
						if (requiredConstructor == null) {
							if (defaultConstructor != null) {
								candidates.add(defaultConstructor);
							}

View on GitHub (pinned to 69bf83ad71)

Solutions

  1. Mark all but one constructor with @Autowired(required=false), leaving exactly zero or one required constructor.
  2. Remove @Autowired from extra constructors entirely — Spring can auto-detect a single constructor without the annotation.
  3. Consolidate to a single constructor that accepts all dependencies.

Example fix

// before
@Autowired
public Foo(DepA a) { ... }

@Autowired
public Foo(DepB b) { ... }

// after
@Autowired
public Foo(DepA a, DepB b) { ... }
Defensive patterns

Strategy: validation

Validate before calling

// At startup or in a test, verify only one required @Autowired constructor exists
Constructor<?>[] ctors = MyBean.class.getDeclaredConstructors();
long requiredCount = Arrays.stream(ctors)
    .filter(c -> c.isAnnotationPresent(Autowired.class))
    .filter(c -> {
        Autowired a = c.getAnnotation(Autowired.class);
        return a.required();
    })
    .count();
if (requiredCount > 1) {
    throw new IllegalStateException("Multiple required @Autowired constructors on " + MyBean.class);
}

Prevention

When it happens

Trigger: A class has two or more constructors annotated with @Autowired where at least one uses the default (required=true). For example: @Autowired public Foo(DepA a) {} and @Autowired public Foo(DepB b) {} — both default to required, triggering the check at line 405-406 where candidates is non-empty and a required constructor is being added.

Common situations: Adding a second constructor with @Autowired during refactoring without realizing the first already carries required=true (the default). Using Lombok @AllArgsConstructor/@RequiredArgsConstructor alongside a hand-written @Autowired constructor. Migrating from field injection to constructor injection and accidentally annotating multiple constructors.

Related errors


AI-assisted analysis of spring-projects/spring-framework@69bf83ad71 (2026-08-09). Data as JSON: /api/errors/dd687335a60827eb. Report an issue: GitHub.