Spring Bean Autowiring Tutorial

Spring » on Sep 3, 2011 { 25 Comments } By Sivateja

Wiring a bean means configuring a bean along with its dependencies into an xml file like previous concepts, by default autowiring is disabled in spring framework.  It means the programmer has to explicitly wire the bean properties into an xml file.

If autowiring is enabled then spring container will take care about injecting the dependencies, programmer no need to configure into an xml file explicitly.  Autowiring is only supported if the dependancies are in the form of objects only, to enable autowiring, we should add autowire attribute to the bean element [or] bean tag, autowire has the following values


  • byName
  • byType
  • Constructor
  • autoDetect
  • none

Let us see each value with one example in the next sessions


You Might Also Like

  ::. About the Author .::

Sivateja Kandula - Java/J2EE Full Stack Developer
Founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog, Love Java and UI frameworks.
You can sign-up for the Email Newsletter for your daily dose of Java tutorials.


25 Responses to “Spring Bean Autowiring Tutorial”
  1. Bhaskar says:

    Thanks a lot for your autowiring examples.. it injects indepency in me 🙂

  2. Java4s says:


    Glad to hear that, you welcome 🙂

  3. suresh says:

    autowire is possible when bean scope is singleton. am i right?

  4. Java4s says:


    Yeah you are correct, default scope is always singleton, you can change the scope with @Scope.

  5. krish says:

    Super Example…….Awesome.

  6. hi java4s team ,
    autowiring concept in spring i got clearly by using our site .
    thanks a lot !

  7. vinayak says:

    In there any need of DI like setter injection if i use @autowired or @resourse.

  8. Pooja says:

    Nicely written article! Good work..

  9. very nice thank u very much

  10. honey says:

    Really amazing sir..

  11. Ashee says:

    Very detailed and neat explanation with good colour text and diagram.
    Great job! Keep it up

  12. NagaSreenu says:

    Hi Java4s Team,

    Can you please add BeanScopes and BeanLifeCycle topics also?

  13. Narasimha says:

    nice blog

  14. pankaj says:

    Really nice platform for java-hungers.
    It is good it u provide the downloading the jar along with code in examples so that code can be easily exceuted in sys.

  15. balamurali says:

    can u please simple example code for Autowiring.

  16. Nagababu says:

    Awesome tutorial……But where the bean scopes!!!!!!!!!

  17. Sumit says:

    cool!!! great tutorial thank you…! that is something i was looking for

  18. venkatesh says:


  19. seshu says:

    hi sivateja garu .
    thanks your doing great help.
    am reading auto wireing am geting confusion.. plese help me
    thank you ,

  20. priya says:

    Good …..thks for such a easy content…

  21. uma mahesh says:

    The best ever explanation for Spring autowiring examples.

  22. akanksha sharma says:

    Sir thank u so much …concepts are clear with the help of u r site

    Sir plz provide Annotation based configuration..

  23. AjayReddy says:

    Hi Sir, can u upload(share) microservices on spring boot


By posting your answer, you agree to our comments policy.
Most Recent Posts from Top Categories
Spring Boot Hibernate Spring
Contact | About Us | Privacy Policy | Advertise With Us

© 2010 - 2024 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.