Annotations simplify matters immensely when it comes to developing Java applications, in this post by Juergen Hoeller he describes a series of annotations that are supported in Spring's 2.5 version and how they benefit those working in and around Java EE 5 design paradigms.
Today I'd like to take a different focus, namely on the wide-ranging set of dependency injection annotations supported by Spring. The following list includes the key annotations that can be used within Spring 2.5 beans: * org.springframework.beans.factory.annotation.Required: Identifies bean property setters that must be called (as opposed to optional setters). Supported since Spring 2.0. * org.springframework.beans.factory.annotation.Autowired: Spring 2.5's central injection annotation, applying to constructors, config methods and fields. Performs injection of components by type, with supporting for "qualifier" annotations that narrow the potential set of candidates in case of multiple matches. * javax.annotation.PostConstruct: JSR-250's common annotation for what Spring calls "init methods". * javax.annotation.PreDestroy: JSR-250's common annotation for what Spring calls "destroy methods". * javax.annotation.Resource: JSR-250's common annotation for injecting an external component by name. A "resource" in JSR-250 terminology really refers to a middleware component such as a DataSource. * @Resource-like, for JAX-WS service lookups, injecting a JAX-WS port proxy. * javax.ejb.EJB: @Resource-like, for EJB Session Bean lookups, injecting an EJB component reference. * javax.persistence.PersistenceUnit: injecting a JPA EntityManagerFactory by persistence unit name. Supported since Spring 2.0. * javax.persistence.PersistenceContext: injecting a JPA EntityManager by persistence unit name. Supported since Spring 2.0. This set of annotations encompasses all of Java EE 5's common annotations, which means that you may use the same common annotations in e.g. Servlet 2.5 servlets, JSF 1.2 managed beans and Spring managed beans. In other words, if you have some standard JSF 1.2 managed beans with annotation usage, you can take them as-is and move their definitions from faces-config to a Spring application context, without any change in the bean classes! This was an important design goal: Spring 2.5 may serve as straightforward replacement of the standard JSF 1.2 managed bean facility, simply through choosing SpringBeanFacesELResolver as your custom JSF ELResolver.
Read Juergen Hoeller's complete post: