Created
September 18, 2014 23:48
-
-
Save jmcgill-public/e05d4378049296f05691 to your computer and use it in GitHub Desktop.
Spring @webfilter not working
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requests for "/module/filtered/controller" do not hit this filter. Why not?