当前位置: 首页 > 知识库问答 >
问题:

为什么spring boot 1.5.3 jar不能识别src/main/resources/meta-inf/resources/中的jsp文件

赏逸春
2023-03-14

那么为什么sprint boot 1.5.3不支持在src/main/resources/meta-inf/resources/中放置jsp文件呢?

共有1个答案

衡翰翮
2023-03-14

在跟踪源代码之后,我发现了为什么1.5.3不能识别jsp文件

Spring boot 1.4.2

//org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.StoreMergedWebXmlListener#onStart
private void onStart(Context context) {
    ServletContext servletContext = context.getServletContext();
    if(servletContext.getAttribute("org.apache.tomcat.util.scan.MergedWebXml") == null) {
        servletContext.setAttribute("org.apache.tomcat.util.scan.MergedWebXml", this.getEmptyWebXml());
    }

    TomcatResources.get(context).addClasspathResources(); // only 1.4.2 has this line 
}

Spring boot 1.5.3

    private void onStart(Context context) {
        ServletContext servletContext = context.getServletContext();
        if (servletContext.getAttribute(MERGED_WEB_XML) == null) {
            servletContext.setAttribute(MERGED_WEB_XML, getEmptyWebXml());
        }
    }
private void onStart(Context context) {
    ServletContext servletContext = context.getServletContext();
    if (servletContext.getAttribute(MERGED_WEB_XML) == null) {
        servletContext.setAttribute(MERGED_WEB_XML, getEmptyWebXml());
    }
    // add below code    
    List<URL> list = new ArrayList<>();
    String file = "file:/Users/zhugw/workspace/boot-jar-serving-jsp/boot-jar-serving-jsp-1.0-SNAPSHOT.jar!/";
    try {
        URL jar = new URL("jar", null, file);
        list.add(jar);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    TomcatResources.get(context).addResourceJars(list);
}
 类似资料: