简体   繁体   English

Grails 2.4过滤器似乎不起作用

[英]Grails 2.4 filters don't seem to be working

I have a Grails 2.4.4 app. 我有一个Grails 2.4.4应用程序。 In it I have the following controllers: 在其中我有以下控制器:

myapp/
    grails-app/
        controllers/
            fizzbuzz/
                FizzController.groovy
                BuzzController.groovy
                ... many others, etc.

I want to create Grails Filters for some of these, so I create a grails-app/conf/WidgetFilters.groovy class: 我想为其中一些创建Grails过滤器 ,所以我创建了一个grails-app/conf/WidgetFilters.groovy类:

class WidgetFilters {
    def filters = {
        fizzFilter(controller: 'fizz*', action: '*') {
            before = {
                println 'I intercepted a called to the Fizz Controller!'  
            }
        }  
        buzzFilter(controller: 'buzz*', action: '*') {
            before = {
                println 'I intercepted a called to the Buzz Controller!'  
            }
        }
    }
}

When I start my app up and go to any Fizz/Buzz actions, I do not see the println . 当我启动我的应用程序并进行任何Fizz / Buzz操作时,我看不到println I've also tried other logging statements (SLF4J) and put other code inside the before closure and am 100% convinced they are not executing. 我还尝试了其他日志语句(SLF4J)并将其他代码置于关闭before并且100%确信它们没有执行。 Have I done something obviously wrong? 我做过一些明显错误的事吗?

Did you tried to restart app + clean build? 你试过重启app + clean build吗?

I've copy-pasted your filters and mock controllers and they're working, here is a code. 我已经复制粘贴过滤器和模拟控制器,它们正在工作, 是一个代码。

Please check out also this properties : 请查看此属性

  • apf.continueChainBefore SuccessfulAuthentication - whether to continue calling subsequent filters in the filter chain apf.continueChainBefore SuccessfulAuthentication之前 - 是否继续调用过滤器链中的后续过滤器
  • fii.observeOncePerRequest - If false allow checks to happen multiple times, for example when JSP forwards are being used and filter security is desired on each included fragment of the HTTP request fii.observeOncePerRequest - 如果false允许多次检查,例如在使用JSP转发时,并且在HTTP请求的每个包含片段上需要过滤器安全性

将课程移至grails-app/conf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM