Grails从计划作业调用控制器方法 [英] Grails Invoke a controller method from a scheduled job

查看:213
本文介绍了Grails从计划作业调用控制器方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的grails应用程序中,我想从一个计划的作业类调用一个控制器中包含的方法。

in my grails application i'd like to invoke from a scheduled job class a method contained in a controller.

阅读这个[http://www.grails .org / Job + Scheduling +(Quartz)],我可以看到,数据源和服务是通过工作类中的名称自动连接的。似乎这是不可能的控制器默认情况下,可能是因为控制器不应该做这种东西。

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,是否有办法获取从grails中的作业调用的控制器方法?

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)?

提前感谢,
Luca

Thanks in advance, Luca

推荐答案

这是坏的做法,因为Controller是用来处理web请求 - 用户会话和一切。

It's bad practice because Controller is intended to handle web requests - with user session and everything.

在Quartz作业中没有用户会话。

There is no user session in Quartz job.

第二,保持Controller中的功能是坏事 - 控制器应该更好地控制其他业务逻辑的调用方法。

Second, keeping functionality in Controller is bad thing on its own - Controller should better only "control" invocations to other business logic method.

我建议您将所有功能移动到服务,域类或POGO类中 src

I'd recommend you to move all the functionality to either a service, domain class or a POGO class in src.

当然,你可以调用 new MyController()。method()将默认注入控制器。

Of course, you can call new MyController().method(), but no beans will be injected into controller by default.

这篇关于Grails从计划作业调用控制器方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆