Monday, January 26, 2015

How to add a filter in Spring Boot

To add a filter in Spring Boot,

you can do the following:

@Bean
public FilterRegistrationBean remoteAddressFilter() {
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
RemoteAddrFilter filter = new RemoteAddrFilter();
// filter.setAllow("127.0.0.1");
filter.setAllow("0:0:0:0:0:0:0:1");
filterRegistrationBean.setFilter(filter);
filterRegistrationBean.addUrlPatterns("/gs/serving-web-content/testParameters");
return filterRegistrationBean;
}

Reference:
http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-embedded-container-servlets-and-filters

No comments:

Post a Comment