[英]Grails 3 Interceptors as a plugin
I'm trying to convert a Grails 2 controller filter into a Grails 3 interceptor. 我正在尝试将Grails 2控制器过滤器转换为Grails 3拦截器。 The interceptor is in a Grails plugin.
拦截器位于Grails插件中。 The Grails 3 upgrade is done, and when I copy and paste the code into an app (just to verify it works), then I see the output from the interceptor.
Grails 3升级已完成,当我将代码复制并粘贴到应用程序中(只是为了验证它是否有效)时,我会看到拦截器的输出。
However, if I try to pull in that code through a plugin to the app, the interceptors do not run. 但是,如果我尝试通过插件将该代码插入应用程序,则拦截器不会运行。 I can verify that the plugin is being pulled;
我可以验证插件是否已被拉出; its interceptors are just not being invoked when I hit an action.
当我点击一个动作时,它的拦截器不会被调用。
For example if the plugin is: 例如,如果插件为:
// If added to app directly, works fine. As plugin, not invoked.
class SimpleInterceptor {
SimpleInterceptor() {
matchAll()
}
boolean before() {
println 'test' // Does not print if using plugin
}
}
And the controller is a simple action: 控制器是一个简单的动作:
def index() {
render 'success'
}
Do I need to register it somehow in order for the interceptor to work on apps? 我需要以某种方式注册它以便拦截器在应用程序上工作吗? Am I missing a step?
我错过了一步吗?
Thanks to @vahid for pointing out a repo that was doing something similar. 感谢@vahid指出了执行类似操作的存储库。 Turns out the issue I had was when I upgraded my plugin's
*Plugin.groovy
file, I didn't extend grails.plugins.Plugin
. 原来是我升级插件的
*Plugin.groovy
文件时没有扩展grails.plugins.Plugin
。 Be sure to do that, or the plugin may not get picked up by apps. 请务必这样做,否则插件可能不会被应用程序接收。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.