Get all updates of Java4s
Follow Us: Email Newsletter

Spring Bean Autowiring Tutorial

Spring » On Sep 3, 2011 { 22 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 Author ♦

Full Stack( Java/J2EE & UI/UX ) Developer and founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog. Sign-up for the Email Newsletter for your daily dose of Java tutorials.


22 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. Raju Kapadne says:

    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…


By posting your answer, you agree to our comments policy.
What would you like to learn today?
Browse these popular technologies
Hibernate spring struts Servlets ajax Log4j jQuery Json Core Java Web Services AngularJs
Most Recent Tutorials
Hibernate_Logo Hibernate Recent Posts Spring_Logo Spring Recent Posts Struts_Logo Struts Recent Posts
Useful Links Current & UpComing Tutorials
  Web Services [ SOAP ], JSP
Contact | About Us | Privacy Policy | Advertise With Us

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