jeudi 5 mars 2015

How to configure spring filters for only paths configured by controller

I have a Spring MVC project and a spring rest project. In both cases, I'm using a filter to add a session ID for SLF4J/Logback logging. However, the filter is getting called for every HTTP request like static files, favicon.ico etc. I know this is happening because I'm using /* in filters. How to prevent this ? I want filter to be called for only for paths handled by my controllers. Here is my filter set in web.xml



<filter>
<filter-name>AppRequestFilter</filter-name>
<filter-class>com.company.appui.filter.AppRequestFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>AppRequestFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


another app where I'm configuring filter in java program



private void registerFilters(Environment environment, ApplicationContext context) {
environment.addFilter(context.getBean(AppRequestFilter.class), "/*");
environment.addFilter(context.getBean(AuthFilter.class), "/*");
}


Sample URL for my spring rest project



localhost:8080/v1/apphealthcheck/epp?token=37e11b48119d


Sample URL for spring MVC project


localhost:28082/app-ui/index.html - home page localhost:28082/app-ui/login - for ajax call from index.html


Aucun commentaire:

Enregistrer un commentaire