Skip to content

Instantly share code, notes, and snippets.

@bs-public
Forked from ekirastogi/SecurityFilter.java
Created June 10, 2018 04:57
Show Gist options
  • Save bs-public/50dbaff1b3eba98c63d07ec5b5cf4158 to your computer and use it in GitHub Desktop.
Save bs-public/50dbaff1b3eba98c63d07ec5b5cf4158 to your computer and use it in GitHub Desktop.
How to define Filter order in Filter Chain in Spring Boot
package com.ekiras.filter;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import javax.servlet.*;
import java.io.IOException;
/**
* Created by ekansh on 22/10/15.
*/
@Component
@Order(1)
public class SecurityFilter implements Filter{
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
System.out.println("###### security filter ");
chain.doFilter(request, response);
}
@Override
public void destroy() {
}
}
package com.ekiras.filter;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import javax.servlet.*;
import java.io.IOException;
/**
* Created by ekansh on 22/10/15.
*/
@Component
@Order(2)
public class TrackingFilter implements Filter{
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
System.out.println("########## tracking filter");
chain.doFilter(request,response);
}
@Override
public void destroy() {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment