How to add a Spring Filter (Not a Grails filter) to a Grails App

Viewed 330

Since Grails is built on Spring, you can add filters two ways: Grails and Spring. Sadly, in 2.5.1, Grails filters only run when there is some non-static resource requested. If you want to run a filter on /assets/videos, like I'm trying to do...It won't work unless you also have a url mapping from /assets/videos to an empty controller action, as well as a filter in some Filters.groovy file.

The Spring way is more low-level: you add a subclass of Filter, perhaps of OncePerRequestFilter. In src/main/groovy/

I read that you can use grails install-templates to get a web.xml in src/templates/web.xml. I added the filter definition in there and ran my app with grails run-app. Disappointingly, my filter was not run as I expected.

The documentation does not cover how to do this so I'm in the dark here. How does one add a normal servlet filter to his grails app?

0 Answers
Related