Spring: Register beans using annotations

Spring 2.5 has added extensive support for annotation-based configuration.

Classes can be annotated to identify them as eligible to be registered as beans in the IoC container. Constructors, fields, methods, and parameters can be autowired by name or type.

Bean Creation

Classes can be annotated and then when they are discovered they will be registered as a bean in the IoC container.

Annotations from org.springframework.stereotype

Annotation Since Version Target Description
@Component Spring 2.5 Class Indicates this class is eligible for registration as a Spring bean when detected by a classpath scanner (context:component-scan).
@Controller Spring 2.5 Class Indicates this class is a Web Controller eligible for registration as a Spring bean when detected by a classpath scanner (context:component-scan). It is a specialized form of@Component.
@Repository Spring 2.0 Class Indicates this class is a Repository (DAO) eligible for registration as a Spring bean when detected by a classpath scanner (context:component-scan). It is a specialized form of @Component.
@Service Spring 2.5 Class Indicates this class is a Service (business service facade) eligible for registration as a Spring bean when detected by a classpath scanner (context:component-scan). It is a specialized form of @Component.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s