Spring , @Resource, @PostConstruct and @PreDestroy

Spring supports JSR-250 which provides @Resource, @PostConstruct and @PreDestroy annotations. @Resource The @Resource annotation is used in the bean class and is attached to the setter methods of the properties. ┬áIt is used to inject a specific bean resource. – will look for a bean with the same name as the property XXX – will…

@Required Spring Annotation

@Required We use the @Required annotation to tell Spring that a property on a bean is required. Student.java Here we have applied the @Required annotation to the method setStudentId. student1.xml This will do nothing if we do not add the RequiredAnnotationBeanPostProcessor bean to our Spring config xml file. TestStudent1.java Now we can bring it all…

Using a Bean PostProcessor for Spring Annotations

I will cover the easy way to do this in a later post, but in this post we will look at how Spring processes annotations. Available JSR-250 Spring Annotations The spring-beans-3.x.jar contains the package org.springframework.beans.factory.annotation. In this package you will find the following BeanPostProcessors: AutowiredAnnotationBeanPostProcessor InitDestroyAnnotationBeanPostProcessor QualifierAnnotationBeanPostProcessor RequiredAnnotationBeanPostProcesor These PostProcessors facilitate the following annotations which…