Skip to content

Instantly share code, notes, and snippets.

@jmcgill-public
Created September 18, 2014 23:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmcgill-public/e05d4378049296f05691 to your computer and use it in GitHub Desktop.
Save jmcgill-public/e05d4378049296f05691 to your computer and use it in GitHub Desktop.
Spring @webfilter not working
import org.springframework.boot.context.embedded.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class TestConfiguration {
@Bean
public FilterRegistrationBean testFilterRegistrationBean() {
ControllerFilter controllerFilter = new ControllerFilter();
FilterRegistrationBean registrationBean = new FilterRegistrationBean();
registrationBean.setFilter(controllerFilter);
return registrationBean;
}
}
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class ControllerTest {
@RequestMapping(value="/module/filtered/controller", method=RequestMethod.GET, produces = "application/json")
@ResponseBody
public HttpEntity<String> test() {
return new ResponseEntity<String>(HttpStatus.OK);
}
}
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
@WebFilter(urlPatterns={"/module/filtered/controller"})
public class ControllerFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
chain.doFilter(request, response);
}
@Override
public void destroy() {
}
}
@jmcgill-public
Copy link
Author

Requests for "/module/filtered/controller" do not hit this filter. Why not?

@nullpjt1
Copy link

nullpjt1 commented Feb 6, 2020

IDK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment