JSP 지원에 대한 스프링 부팅 제한
JSP의 지원을 위해 Spring Boot는 포장 방법 만 지원하며 Fat Jar를 지원하지 않습니다. 공식 문서를 참조하십시오 : https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-developing-web-applications.html#boot-features-jsp-limitations
여기서 Spring Boot는 공식적으로 Tomcat의 문제라고 말하지만 실제로는 Spring Boot 자체가 포장 형식을 변경하여 발생합니다. 이전 기사를 참조하십시오 : http://www.vevb.com/article/141479.htm
원래 구조에서 Tomcat은 Fat Jar의 META-INF/resources 디렉토리 아래에서 자원을 스캔 할 수 있습니다. BOOT-INF/classes 추가 한 후 Tomcat은 스캔 할 수 없습니다.
그렇다면이 문제를 해결하는 방법은 무엇입니까? 다음은 Spring Boot Fat Jar/Exploded Directory의 JSP를 지원하는 솔루션입니다.
Tomcat을 개인화하고 Tomcat의 Resources 세트에 Boot-Inf/클래스를 추가하십시오
Tomcat에서는 모든 스캔 된 리소스가 소위 ResourceSet 에 배치됩니다. 예를 들어, Servlet 3 사양에있는 Application Jar 패키지의 META-INF/resources ResourceSet 입니다.
이제 스프링 부트로 강타한 Fat Jar의 BOOT-INF/classes 디렉토리를 ResourceSet 에 추가 할 수있는 방법을 찾아야합니다.
다음으로 Tomcat의 LifeCyclElistener 인터페이스를 구현하여 LifeCycle.configure_start_event 이벤트에서 Boot-Inf/Classes의 URL을 얻은 다음이 URL을 Webresourceset에 추가하십시오.
/*** 메인 클래스 FAT JAR/폭발 디렉토리를 Tomcat Resources 세트에 추가합니다. * * @Author HengyUnabc 2017-07-29 * */public class staticResourceConfigurer는 LifeCyclelistener {개인 최종 컨텍스트 컨텍스트; staticResourceConfigurer (Context Context) {this.context = 컨텍스트; } @override public void lifecycleevent (lifecycleevent event) {if (event.getType (). equals (lifecycle.configure_start_event)) {url location = this.getClass (). if (resourceutils.isfileurl (location)) {// exploded 디렉토리로 실행될 때 ritfile = location.getfile (); if (rootfile.endswith ( "/boot-inf/classe/")) {rootfile = rootfile.substring (0, rootfile.length ()-"/boot-inf/classe/". length () + 1); } if (! 새 파일 (루트 파일, "meta-inf" + file.separator + "resources"). isdirectory ()) {return; } try {location = new File (rootfile) .touri (). tourl (); } catch (marformedurlexception e) {throw new neveralstateException ( "Tomcat Resources를 추가 할 수 없음", e); }} 문자열 locationstr = location.toString (); if (locationstr.endswith ( "/boot-inf/classe!/")) {// fat jar locationstr = locationst.substring (0, locationstr.length ()-"/boot-inf/class!/". length () + 1); try {location = new URL (locationstr); } catch (marformedurlexception e) {throw new neveralstateException ( "Tomcat Resources를 추가 할 수 없음", e); }} this.context.getResources (). CreateWebResourceset (racussEtType.Resource_jar, "/", 위치, "/meta-inf/resources"); }}}Spring Boot Embedded Tomcat을로드하기 위해서는이 staticResourceConfigurer, EmbeddedServletContainerCustomizer 구성이 필요합니다.
@configuration @컨디셔닝 @컨디셔닝 @컨디셔닝 (namcat.staticresourcecustomizer.enable) customize (contiblembeddedservletcontainer container) {if (tomcatembeddedservletcontainerfactory) {((tomcatembeddedservletcontainerfactory) 컨테이너의 컨테이너 인스턴스. context.addlifecyclelistener (new staticResourceConfigurer (context)}); }}}; }}이러한 방식으로 Spring Boot는 Fat Jar에서 JSP 리소스를 지원할 수 있습니다.
데모 주소 : https://github.com/hengyunabc/spring-boot-fat-jar-jsp-sport
요약
BOOT-INF/classes 로 스캔 할 수 없습니다.ResourceSet StaticResourceConfigurer Fat Jar에서 /BOOT-INF/classes 추가하여 문제를 해결하십시오.위는이 기사의 모든 내용입니다. 모든 사람의 학습에 도움이되기를 바랍니다. 모든 사람이 wulin.com을 더 지원하기를 바랍니다.