FilterRegistrationBean is deprecated in Spring Boot 1.4.*
<p>I upgraded Spring Boot dependency in my project and I realized that some classes, such as FilterRegistrationBean, are deprecated. </p>

<p>Do you know how can implement a Filter in Spring Boot 1.4.1?</p>

<p>Bean of Filter</p>

<pre><code>@Bean
public FilterRegistrationBean filterRegistrationBean() {
    AuthenticationFilter f = new AuthenticationFilter();
    FilterRegistrationBean registrationBean = new FilterRegistrationBean();
    registrationBean.setFilter(f);
    registrationBean.addInitParameter("defaultToken", defaultToken);
    registrationBean.addInitParameter("secretKey", secretKey);
    ArrayList&lt;String&gt; match = new ArrayList&lt;&gt;();
    match.add("/users/*");
    registrationBean.setUrlPatterns(match);
    return registrationBean;
}
</code></pre>

<p>My Filter code:</p>

<pre><code>public class AuthenticationFilter implements Filter {

private String defaultToken;
private String secretKey;

private UserSessionTokenRepository userSessionTokenRepository;
private UserManager userManager;

@Override
public void init(FilterConfig filterConfig) throws ServletException {
    defaultToken = filterConfig.getInitParameter("defaultToken");
    secretKey = filterConfig.getInitParameter("secretKey");
    userSessionTokenRepository = WebApplicationContextUtils.getRequiredWebApplicationContext(filterConfig.getServletContext()).getBean(UserSessionTokenRepository.class);
    userManager = WebApplicationContextUtils.getRequiredWebApplicationContext(filterConfig.getServletContext()).getBean(UserManager.class);
}

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;
    chain.doFilter(request, response);
}

public void addHeaders(HttpServletResponse response) {
    response.setHeader("Access-Control-Allow-Origin", "*");
    response.setHeader("Access-Control-Allow-Methods", "POST, PUT, GET, OPTIONS, DELETE");
    response.setHeader("Access-Control-Max-Age", "3600");
    response.setHeader("Access-Control-Allow-Headers", "Content-Type");
}

public void destroy() {
}
}
</code></pre>