Is it possible to use a profile based filter in your web.xml ? For example
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
<init-param>
<param-name>spring.profiles.active</param-name>
<param-value>secured</param-value>
</init-param>
</filter>
I know this is possible for servlets, but I cant seem to get it to work for filters.
Thanks
Original Answer
Filters use the ApplicationContext loaded from the ContextLoaderListener, so the
<init-param>to the Filter is not used. Instead, you will want to use one of the ways of activating the profile for the ContextLoaderListener. One way is to use a as shown below:Follow Up
Following up based upon the comments. There is no way to omit the Filter using Spring profiles since the web.xml will always load the DelegatingFilterProxy which always tries to load its delegate. If the delegate is missing you will get an error. Instead, you can create a profile that disable Spring Security as shown below:
You could then disable Spring Security by activating the insecure profile in your web.xml as shown below.
If you are not using Spring Security you can disable the Filter by creating a Filter that does nothing but continue the FilterChain an placing that in the disabled profile. For example: