springboot 에서 jsp-config include 사용
spring의 web.xml에 설정되어 있는 전역 사용 jspf파일을 springboot java 코드로 변환하는 방법
기존코드
<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<include-prelude>/WEB-INF/views/common/layout/taglib/comTaglibs.jspf</include-prelude>
</jsp-property-group>
</jsp-config>
변경코드
import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.Context;
import org.apache.tomcat.util.descriptor.web.JspConfigDescriptorImpl;
import org.apache.tomcat.util.descriptor.web.JspPropertyGroup;
import org.apache.tomcat.util.descriptor.web.JspPropertyGroupDescriptorImpl;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import java.util.Collections;
@Component
@Slf4j
public class ServletInitailizer extends SpringBootServletInitializer {
@Bean
public ConfigurableServletWebServerFactory configurableServletWebServerFactory ( ) {
return new TomcatServletWebServerFactory() {
@Override
protected void postProcessContext(Context context) {
super.postProcessContext(context);
JspPropertyGroup jspPropertyGroup = new JspPropertyGroup();
jspPropertyGroup.addUrlPattern("*.jsp");
jspPropertyGroup.addUrlPattern("*.jspf");
jspPropertyGroup.setPageEncoding("UTF-8");
jspPropertyGroup.setScriptingInvalid("true");
jspPropertyGroup.addIncludePrelude("/WEB-INF/views/common/layout/taglib/comTaglibs.jspf");
jspPropertyGroup.setTrimWhitespace("true");
jspPropertyGroup.setDefaultContentType("text/html");
JspPropertyGroupDescriptorImpl jspPropertyGroupDescriptor = new JspPropertyGroupDescriptorImpl(jspPropertyGroup);
context.setJspConfigDescriptor(new JspConfigDescriptorImpl(Collections.singletonList(jspPropertyGroupDescriptor), Collections.emptyList()));
}
};
}
}
'개발 > Spring' 카테고리의 다른 글
QueryDsl date between 사용 (0) | 2021.04.03 |
---|---|
Springboot @Transactional Rollback 이 안되는 현상 정리 (0) | 2021.03.24 |
JSONException 에러 관련 (0) | 2020.08.18 |
Xss custom filter (lucy 적용 안되어 임시방편 코드) (0) | 2020.07.28 |
@Slf4j 사용시 log cannot be resolved 에러 처리 (4) | 2019.09.18 |