in my grails application i’d like to invoke from a scheduled job class a method contained in a controller.
Reading this [http://www.grails.org/Job+Scheduling+(Quartz)], I can see that datasources and services are auto-wired by name in job classes. It seems this is not possible for controllers by default, probably ’cause controllers aren’t supposed to do this kind of stuff.
BTW, is there a way to get a controller method called from a job in grails?
And could this be such a bad practice to you (and why)?
Thanks in advance,
Luca
It’s bad practice because Controller is intended to handle web requests – with user session and everything.
There is no user session in Quartz job.
Second, keeping functionality in Controller is bad thing on its own – Controller should better only “control” invocations to other business logic method.
I’d recommend you to move all the functionality to either a service, domain class or a POGO class in
src.Of course, you can call
new MyController().method(), but no beans will be injected into controller by default.