Spring - Implicit constructor Injection

[Last Updated: Feb 8, 2017]

Starting Spring 4.3, it is no longer necessary to specify the @Autowired annotation if the target bean only defines one constructor.

As we saw in different ways of DI example project, that we have to use @Autowired on the constructor if we are scanning the component classes. Now we can skip that i.e. @Autowired is no longer required.

Let's see the example project to understand what's that new change in Spring4.3.

Example Project

Dependencies and Technologies Used:

  • Spring Context 4.3.2.RELEASE: Spring Context.
  • JDK 1.8
  • Maven 3.0.4

Implicit Constructor Injection Select All Download
  • spring-implicit-constructor-injection
    • src
      • main
        • java
          • com
            • logicbig
              • example
                • client
                • service
                  • impl

    @Configuration class support for constructor injection

    Prior to Spring 4.3, constructor injection wasn't supported for @Configuration classes. They are supported now and additionally they can skip the @Autowired annotation if there's only one constructor in the configuration class. Please see in above example project.

    See Also