Writing custom filters for Play! 2.2 in Java

后端 未结 3 832
别那么骄傲
别那么骄傲 2020-12-09 05:06

I have a simple scenario: automatically add a response header to every HTTP response; and I want to do this in Java.

Looking at src/play-filters-helpers/src/ma

3条回答
  •  难免孤独
    2020-12-09 05:54

    To add a custom filter (MyFilter.class) create a Global.java file in the root package. Tested in PlayFramework 2.3.x and Java (JDK8)

    import play.GlobalSettings;
    import play.api.mvc.EssentialFilter;
    
    public class Global extends GlobalSettings {
        @Override
        public  Class[] filters() {
            return new Class[]{MyFilter.class};
        }
    }
    

提交回复
热议问题