- security로 인한 한글 깨짐 해결하기
- WebConfig.java
package works.yermi.config;
// import 생략
public class WebConfig extends AbstractAnnotationConfigDispatcherServletInitializer{
// 코드 생략
@Override
protected Filter[] getServletFilters() {
// TODO Auto-generated method stub
CharacterEncodingFilter encodingFilter = new CharacterEncodingFilter("utf-8");
encodingFilter.setForceEncoding(true);
return new Filter[] {encodingFilter};
}
}
- Securityinitializer.java
package works.yermi.config;
import javax.servlet.FilterRegistration;
import javax.servlet.ServletContext;
import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer;
import org.springframework.web.filter.CharacterEncodingFilter;
public class Securityinitializer extends AbstractSecurityWebApplicationInitializer{
@Override
protected void beforeSpringSecurityFilterChain(ServletContext servletContext) {
FilterRegistration.Dynamic characterEncodingFilter = servletContext.addFilter("encodingFilter", new CharacterEncodingFilter());
characterEncodingFilter.setInitParameter("encoding", "UTF-8");
characterEncodingFilter.setInitParameter("forceEncoding", "true");
characterEncodingFilter.addMappingForUrlPatterns(null, false, "/*");
}
}