- 전체
- JAVA 일반
- JAVA 수학
- JAVA 그래픽
- JAVA 자료구조
- JAVA 인공지능
- JAVA 인터넷
- Java Framework
- Java GUI (AWT,SWING,SWT,JFACE)
- SWT and RCP (web RAP/RWT)[eclipse], EMF
Java Framework [Spring boot] Spring boot 에서 Filter 사용하기
2021.06.18 13:12
[Spring boot] Spring boot 에서 Filter 사용하기
Spring boot 서블릿/필터 시리즈
Spring boot에서 Servlet 사용하기
- /dev?tn=502 Spring boot에서 Filter 사용하기 /dev?tn=503
Bean 등록
스프링부트에서는 web.xml 이 더 이상 사용되지 않아 서블릿이나 필터를 org.springframework.boot.web.servlet 의 RegistrationBean 을 통해 등록해야합니다.
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class FilterConfig
{
@Bean
public FilterRegistrationBean getFilterRegistrationBean()
{
FilterRegistrationBean registrationBean = new FilterRegistrationBean(new HSTSFilter());
// registrationBean.addUrlPatterns("/*"); // 서블릿 등록 빈 처럼 패턴을 지정해 줄 수 있다.
return registrationBean;
}
}
HelloFilter 예제
public class HelloFilter implements Filter
{
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
throws IOException, ServletException
{
// 필터적용
((HttpServletResponse)res).setHeader("HelloHeader", "test");
chain.doFilter(req, res);
}
@Override
public void destroy()
{
}
@Override
public void init(FilterConfig fc) throws ServletException
{
}
}
[출처] https://gs.saro.me/dev?tn=503
본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.