Spring 3 and JSR-330 Annotation : @Named and @Component Difference

SHARE & COMMENT :

@Named and @Component annotations are used for the same purpose. Both the annotations are used for enabling a class to be auto detected as the bean definition for spring’s application context. The following are the main different of these two annotations.

  1. @Named is part of the. Java specification. It is more recommended since this annotation is not tied to spring APIs. If you migrate your applications, you can continue use this annotation.
  2. @Component is part of the spring’s annotations library. It is similar to the @Named annotation in functionality.
package javabeat.net.core.ioc;

@Named
public class SpringBeanNamed {

}

@Component("beanName")
public class SpringBeanComponent {

}

Comments

comments

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Speak Your Mind

*

Close
Please support the site
By clicking any of these buttons you help our site to get better