Is context:annotation-config an alternative to @AutoWired?

Posted by Antacid on Stack Overflow See other posts from Stack Overflow or by Antacid
Published on 2010-06-06T17:02:20Z Indexed on 2010/06/06 17:42 UTC
Read the original article Hit count: 263

Filed under:
|
|
|

Is it correct that I can put context:annotation-config in my XML config and it will automatically inject the bean class without needing any annotations?

So instead of using these annotation types:

public class Mailman
{
    private String name;

    @Autowired
    private Parcel Parcel;

    public Mailman(String name)
    {
        this.name = name;
    }

    @Autowired
    public void setParcel(Parcel Parcel)
    {
        this.Parcel = Parcel;
    }

    @Autowired
    public void directionsToParcel(Parcel Parcel)
    {
        this.Parcel = Parcel;
    }

}

I would just need to write this:

<beans ... >
<bean id="mailMan" class="MailMan">
 <constructor-arg value="John Doe"/>
</bean>
<bean id="parcel" class="Parcel" />
<context:annotation-config />
</beans>

and then my MailMan class would look a lot simpler without the need for annotations:

public class Mailman
{
    private String name;

    private Parcel Parcel;

    public Mailman(String name)
    {
        this.name = name;
    }    
}

© Stack Overflow or respective owner

Related posts about java

Related posts about spring