无法在 WebSphere 上使用 SpringBoot 应用程序 运行 找到 webjars

Cannot locate webjars with SpringBoot application running on WebSphere

我一直在尝试在 WebSphere 服务器上托管 Spring 启动应用程序。

版本:

该应用已成功部署在独立 Tomcat 9.0.22 上,并且可以在那里解析 webjars。但是,对于 WebSphere,我在尝试从 html 页面访问 webjars 时收到错误消息:

2019-08-05 10:43:11.839 DEBUG 1 --- [ecutor-thread-6] o.s.web.servlet.DispatcherServlet        : GET "/appcontext/webjars/jquery/jquery.min.js", parameters={}
2019-08-05 10:43:11.845 DEBUG 1 --- [ecutor-thread-6] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped to ResourceHttpRequestHandler ["classpath:/META-INF/resources/webjars/"]
2019-08-05 10:43:11.849 DEBUG 1 --- [ecutor-thread-6] o.s.w.s.r.ResourceHttpRequestHandler     : Resource not found
2019-08-05 10:43:11.849 DEBUG 1 --- [ecutor-thread-6] o.s.web.servlet.DispatcherServlet        : Completed 404 NOT_FOUND

webjars 模式被 Spring 成功映射:

2019-08-05 10:43:09.039 DEBUG 1 --- [ecutor-thread-6] o.s.w.s.handler.SimpleUrlHandlerMapping  : Patterns [/webjars/**, /**] in 'resourceHandlerMapping'

解决方案是添加 classloading 条目,将 useJarUrls 属性设置为 true,到 WebSphere server.xml 文件:

<server description="myServer">
    <featureManager>
        <feature>servlet-3.0</feature>
    </featureManager>
    <classloading useJarUrls="true"/> <!-- this line was added -->
    <httpEndpoint httpPort="9080" httpsPort="9443" host="*" id="defaultHttpEndpoint"/>
</server>

这个 IBM support issue 对解决这个问题特别有帮助。