When it comes to Spring specific pros and cons:

  • Constructor injection (from the definition) does not allow you to create circular dependencies between beans. This limitation is actually an advantage of constructor injection - Spring can resolve circular dependencies when setter injection is used without you even noticing.

  • On the other hand if you use constructor injection CGLIB is not able to create a proxy, forcing you to either use interface-based proxies or a dummy no-arg constructor. See: SPR-3150

Answer from Tomasz Nurkiewicz on Stack Overflow
🌐
Blogger
javarevisited.blogspot.com › 2012 › 11 › difference-between-setter-injection-vs-constructor-injection-spring-framework.html
Difference between Setter vs Constructor Injection in Spring
Setter Injection is the preferred choice when a number of dependencies to be injected is a lot more than normal, if some of those arguments are optional than using a Builder design pattern is also a good option.
🌐
Spring
spring.io › blog › 2007 › 07 › 11 › setter-injection-versus-constructor-injection-and-the-use-of-required
Setter injection versus constructor injection and the use of @Required
July 11, 2007 - There is a lot to be said about constructor injection versus setter injection and I know a lot of people still prefer setter injection. I think though (and with me a lot of people) that constructor injection in combination with checking dependencies in your constructor is the better way (for code that does not have a lot of optional and configurable values or collaborators) to enforce checking of required dependencies.
Discussions

dependency injection - Setter DI vs. Constructor DI in Spring? - Stack Overflow
Unfortunately, Spring has trained ... much better. Today, we're freed from those constraints, thus allowing it to be a design decision again. Your beans should use constructor injection for any dependencies that are required by the bean and setter injection for dependencies that are optional and have a reasonable default, more or less as OOD has been telling us from the beginning. ... Thanks Ryan.As you ... More on stackoverflow.com
🌐 stackoverflow.com
java - Explain why constructor inject is better than other options - Stack Overflow
In a Pro Spring 3 Book, Chapter 4 - Introduction IOC and DI in Spring - Page 59, In "Setter Injection vs. Constructor Injection" section, a paragraph says Spring included, provide a mechanism for More on stackoverflow.com
🌐 stackoverflow.com
When to use Constructor Injection vs. Setter Injection
Never use setter injection. At least, never use it as much as possible. Reason being that it encourages mutability. You should always aim for complete immutability. More on reddit.com
🌐 r/SpringBoot
11
7
March 18, 2023
Field injection is fine, convince me otherwise
Immutability. Constructor injection into private final fields makes the injected properties of your classes immutable, making runtime behaviour more predictable. **Edit there's some valid criticism of this post below, my comment is not well worded and could easily be misconstrued. More on reddit.com
🌐 r/java
211
21
September 8, 2023
🌐
TutorialsPoint
tutorialspoint.com › difference-between-constructor-injection-and-setter-injection-in-spring
Difference Between Constructor Injection and Setter Injection in Spring
Let’s say Class X is tightly dependent on Class Y then we should use constructor based injection. Setter based Injection - It can be used by calling setter methods on your beans.
Top answer
1 of 7
100

A class that takes a required dependency as a constructor argument can only be instantiated if that argument is provided (you should have a guard clause to make sure the argument is not null) (or use a non-nullable type in Kotlin). A constructor therefore enforces the dependency requirement whether or not you're using Spring, making it container-agnostic.

If you use setter injection, the setter may or may not be called, so the instance may never be provided with its dependency. The only way to force the setter to be called is using @Required or @Autowired , which is specific to Spring and is therefore not container-agnostic.

So to keep your code independent of Spring, use constructor arguments for injection. This applies to tests; you'll have an easier time instantiating and testing the class in a normal unit test, without needing to configure an application context or the complexity that comes along with setting up an integration test.

Update: Spring 4.3 will perform implicit injection in single-constructor scenarios, making your code more independent of Spring by potentially not requiring an @Autowired annotation at all.

2 of 7
19

(...) by using Constructor Injection, you assert the requirement for the dependency in a container-agnostic manner

This mean that you can enforce requirements for all injected fields without using any container specific solution.


Setter injection example

With setter injection special spring annotation @Required is required.

@Required

Marks a method (typically a JavaBean setter method) as being 'required': that is, the setter method must be configured to be dependency-injected with a value.

Usage

import org.springframework.beans.factory.annotation.Required;

import javax.inject.Inject;
import javax.inject.Named;

@Named
public class Foo {

    private Bar bar;

    @Inject
    @Required
    public void setBar(Bar bar) {
        this.bar = bar;
    }
}

Constructor injection example

All required fields are defined in constructor, pure Java solution.

Usage

import javax.inject.Inject;
import javax.inject.Named;

@Named
public class Foo {

    private Bar bar;

    @Inject
    public Foo(Bar bar) {
        this.bar = bar;
    }

}

Unit testing

This is especially useful in Unit Testing. Such kind of tests should be very simple and doesn't understand annotation like @Required, they generally not need a Spring for running simple unit test. When constructor is used, setup of this class for testing is much easier, there is no need to analyze how class under test is implemented.

🌐
www.java4coding.com
java4coding.com › contents › spring › setter-vs-constructor-injection
Setter vs Constructor Injection - java4coding
If there is only one property in a spring bean class then use constructor injection as constructor executes before methods constructor injection will be faster than setter injection. If spring bean class is having more than one property then it is better to use setter injection because it reduces ...
Find elsewhere
🌐
Quora
quora.com › Which-is-better-constructor-injection-or-setter-dependency-injection
Which is better: constructor injection or setter dependency injection? - Quora
Answer (1 of 2): Constructor Injection is Better. If you want to instantiate a class you always do it with its constructor. So if you are using constructor based injection, the only way to instantiate the class is through that constructor.
🌐
Medium
medium.com › @nikhilsalvi011 › setter-vs-constructor-injection-c55d9434dc20
Setter vs Constructor Injection. We have covered both setter injection… | by Nikhil Sambhaji Salvi | Medium
January 29, 2024 - If there is only one property in a spring bean class then use constructor injection as constructor executes before methods constructor injection will be faster than setter injection.
🌐
GeeksforGeeks
geeksforgeeks.org › springboot › spring-setter-injection-vs-constructor-injection
Spring - Setter Injection vs Constructor Injection - GeeksforGeeks
July 23, 2025 - Instead of having a constructor, here we have a setter method that injects the dependency because its annotated with @Autowired. ... And finally, the dependencies are injected through setter method. Note: Its not necessary that we can only use setter method to inject dependencies instead, we can annotate any method with @Autowired and it'll work as a dependency injection · Any method name will work as long as the method that's injecting dependencies is annotated with @Autowired
🌐
Javatpoint
javatpoint.com › difference-between-constructor-and-setter-injection
Difference between Constructor and Setter injection in spring - javatpoint
May 1, 2013 - It internally uses setter or constructor injection. can't be used to inject primitive and string values. It works with reference only. Advantage of It requires the less code because we don't need... ... IoC Container IoC Container Using BeanFactory Using ApplicationContext The IoC container is responsible to instantiate, configure and assemble the objects.
🌐
LinkedIn
linkedin.com › all › microservices
What are the benefits and drawbacks of using constructor injection vs setter injection in microservices?
December 21, 2023 - If you hide the design smell by avoiding Constructor Injection, you don't tackle the root problem. If your unit under test is hard to test because of the TestDoubles you need to provide, you're probably overusing them. There are only 2 reasons for using TestDoubles : your tests are to slow and/or not isolated. In any case, your problem is the object creation design. …see more ... Setter injection is the practice of passing the dependencies of a microservice as arguments to its setter methods.
🌐
Smartprogramming
smartprogramming.in › tutorials › spring-framework › difference-between-constructor-injection-and-setter-injection-in-spring
Constructor Injection vs Setter Injection in Spring
Constructor Injection is generally better for required dependencies, as it ensures that objects are created with all necessary dependencies. This improves code reliability and makes it clear that the dependency is mandatory. Setter Injection is preferable for optional dependencies or cases ...
🌐
amitph
amitph.com › home › spring › spring dependency injection – field vs setter vs constructor injection
Spring Dependency Injection - Field vs Setter vs Constructor Injection | amitph
November 22, 2024 - Field Injection: The Best. Less boilerplate code. The focus is on business logic. Constructor Injection: Better. Constructors visually stand separate from methods. Setter Injection: Worst.
🌐
LinkedIn
linkedin.com › all › engineering › software design
How do you choose between constructor, setter, and field injection in Java?
March 22, 2023 - It can make your class mutable and vulnerable to inconsistent states, as the dependencies can be changed or nullified after the class is created. Setter injection also makes your code less readable, as you cannot tell what dependencies a class ...
🌐
Java Code Geeks
javacodegeeks.com › home › enterprise java
Spring Dependency Injection – Field vs Setter vs Constructor Injection - Java Code Geeks
February 18, 2019 - Field Injection: The Best. Less boilerplate code. Focus is on business logic. Constructor Injection: Better. Constructors visually stand separate from methods. Setter Injection: Worst. Added 4 instance methods.
🌐
Medium
saannjaay.medium.com › difference-between-constructor-and-setter-injection-in-spring-or-spring-boot-59b075a8a6b6
Difference between constructor and setter injection in Spring or Spring Boot
March 5, 2025 - Which one is better? 🤔 When should you use constructor injection over setter injection, and vice versa? Let’s break it down! Dependency Injection is a design pattern that allows Spring to inject required dependencies into a class rather than creating them manually.
🌐
Medium
medium.com › @miguelangelperezdiaz444 › dependency-injection-in-spring-constructor-property-or-setter-which-one-should-i-choose-d38be824c8c1
💉Dependency Injection in Spring: Constructor, Property, or Setter? Discover the Best Option for Your Project! | Medium
April 5, 2023 - In addition, injecting dependencies through the constructor avoids the potential problems of property or method-based dependency injection techniques. However, there are cases where dependency injection through properties or setters can be useful.
🌐
Medium
medium.com › @programmingsolutions750 › constructor-injection-vs-setter-injection-spring-interview-question-explained-with-examples-e09dc53ed3d2
Constructor Injection vs Setter Injection: Spring Interview Question Explained with Examples | by FullStack With Ram | Medium
September 29, 2025 - While both serve the same purpose — injecting dependencies — they differ in when and how dependencies are assigned, leading to different design choices. Constructor Injection enforces immutability and ensures mandatory dependencies, whereas ...
🌐
Reflectoring
reflectoring.io › constructor-injection
Why You Should Use Constructor Injection in Spring
March 28, 2020 - When we have a class with multiple constructors, we need to explicitly add the @Autowired annotation to any one of the constructors so that Spring knows which constructor to use to inject the dependencies. In setter-based injection, we provide the required dependencies as field parameters to the class and the values are set using the setter methods of the properties.