Doing transactional work in Spring service using @PostConstruct method

Apparently, the @PostConstruct idiom in Spring / JSE isn't that well defined: If you have a service class annotated with @Transactional and a method defined as @PostConstruct tries to do transactional work (calling on DAOs, for instance), it will fail due to non existing transaction in context, sad as true.


Yeah, you could add some boolean init member and check it on every invocation of every service method, perhaps even via an interceptor, but why not use a new annotation that causes a method to get called after the object is fully initialized?

 

Well, high time to meet @PostInitialize. It'll do just that. Written by jbaruch, published on Spring forums and patched by yours truely:

 

http://forum.springsource.org/showthread.php?p=252616#post252616

 

Thank you for your interest!

We will contact you as soon as possible.

Send us a message

Oops, something went wrong
Please try again or contact us by email at info@tikalk.com