Friday, August 24, 2012

Spring Auto-Wiring Beans with @Autowired annotation

In Spring, you can use @Autowired annotation to auto wire bean on the setter method, constructor or a field.

There are two ways to can achieve it :
1.Using <context:annotation-config />
    Just Add Spring context and <context:annotation-config /> in bean configuration file

<beans xmlns=""
    xmlns:xsi="" xmlns:p=""

    <context:annotation-config />

2. Using AutowiredAnnotationBeanPostProcessor
Add 'AutowiredAnnotationBeanPostProcessor' directly in your bean configuration file.

And in Class, Just add annotation @Autowired above the setter function as seen below , You can do the same on constructor too:
class A {
private B b;

   public void setB(B b) {
      this.b = b;

No comments:

Post a Comment

How TOPT Works: Generating OTPs Without Internet Connection

Introduction Have you ever wondered how authentication apps like RSA Authenticator generate One-Time Passwords (OTPs) without requiring an i...