简体   繁体   中英

Grails 2.4 filters don't seem to be working

I have a Grails 2.4.4 app. 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:

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 . I've also tried other logging statements (SLF4J) and put other code inside the before closure and am 100% convinced they are not executing. Have I done something obviously wrong?

Did you tried to restart 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
  • 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

将课程移至grails-app/conf

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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