Java EE annotations in Spring

Since I began programming I noticed that annotations kept gaining popularity. Implementing a marker interface is in many cases replace by adding an Annotation.

Even in Spring. Spring added the support tor the java EE annotations. Here’s a little example. Instead of implementing the initializingBean Interface, you can simply use theĀ @PostConstruct van Java EE 5.

All callback handler used in EE5+ are possible in Spring. you only have to configure theĀ CommonAnnotationBeanPostProcessor in your spring context.

/** {@inheritDoc} */
public void afterPropertiesSet() throws Exception {
}

becomes

/** Postconstuction method */
@PostConstruct
public void myMethod() {
}

It is a small nuance, but I personally like this way of working. I don’t chose annotations over interfaces in every case, but when we are talking about callback handlers, I think it the better way. Your implementation doesn’t include strange spring specific methods, but methods that make sense to you and your other developers. It just has a little annotation above it.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>