Tuesday, 15 February 2011

spring - @PostConstruct fails silently on a Grails Service -



spring - @PostConstruct fails silently on a Grails Service -

i thought spring annotations supposed work out of box in grails environment, cannot work @ all. tried afterproperties method, did not work either.

can spot mistake? there configuration need do?

package dashboard import javax.annotation.postconstruct class emailjobschedulerservice { def grailsapplication @postconstruct def init() { def cronexpression = grailsapplication.config.emailat8amtrigger println(cronexpression) emailsubscribersjob.schedule(cronexpression, new hashmap()) } }

try changing to

@postconstruct void init() {

(i.e. void instead of def). i'm not sure whether spring enforces specification of @postconstruct states among other things "the homecoming type of method must void".

edit: uchamp's comment correct, tried same test , indeed @postconstruct annotated method called first time service bean used and, not @ startup. can add

static lazyinit = false

to service class forcefulness initialized eagerly @ startup. doesn't appear documented in user guide, deduced reading code.

note "used" in previous paragraph doesn't mean have phone call method on it. service bean initialized first time fetched application context, either straight or because has been autowired bean beingness initialized. example, injecting service bootstrap using

def emailjobschedulerservice

would plenty fire @postconstruct method, don't have phone call of service's methods bootstrap.init closure. similarly, if service injected controllers init fire first time 1 of controllers handled request (any request, doesn't have action calls service).

spring grails annotations postconstruct

No comments:

Post a Comment