@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.
- @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.
- @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 { }