I know how constructor and setter injection works in spring.

Normally I use interfaces instead of classes to inject beans using setter and I consider it as interface injection, but in case of constructor we also use interfaces (I am confused). In following example I use JobProcessor interface instead of JobProcessorImpl class.

public class JobScheduler {
    // JobProcessor interface
    private JobProcessor jobProcessor;
    // Dependecy injection
    public void setJobProcessor(JobProcessor jobProcessor){
        this.jobProcessor = jobProcessor;

I tried to find a solution by googling but there are different opinions by writers. Even some people says that spring doesn't support interface injection in their blogs/statements.

Can someone help me by example?

1 Answer 1


In interface injection, the setter method is provided by an interface that is implemented by the bean in which we are going to inject the dependency.


package some.package;
public class Car implements EngineMountable {
    private Engine engine;
    @Override //dependency injection
    public void mount(Engine engine){
        this.engine = engine;

public interface EngineMountable {
    void mount(Engine engine);

The same is working for me in spring by applying the following configuration:

<bean name="car" class="some.package.Car">
    <property name="mount" ref="engineObject" />

In some sites people says that spring does not supports interface injection, but for me the above example works in spring. As per me : spring supports interface injection.

Reference : Martin Fowler : Interface Injection

  • 2
    I don't see the difference between this and "setter injection", other than that the "setter" method is specified in an interface here. Fundamentally, the two are basically identical. Am I wrong? Could you clarify the answer by contrasting this with "setter injection"?
    – Jez
    Apr 3, 2014 at 9:38
  • @Satish Could you give me complete Example for this?
    – sunleo
    Sep 22, 2014 at 17:35
  • 5
    I disagree with this answer. According to Fowler's definition, a container using Interface Injection uses the declared interfaces of a class to identify what needs to be injected into it, thus avoiding a need to configure each concrete class, and rather just configuring the interface (which could be implemented by many classes). In your example, you provide configuration for the concrete class, and if you added another implementation of EngineMountable would need to add extra configuration for that, too.
    – Jules
    Jan 20, 2015 at 10:00
  • Spring does not support interface injection as per their docs springbyexample.org/examples/…
    – jawath
    Mar 3, 2020 at 11:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.