Spring 开机时 jawr 不工作

Spring boot with jawr not working

我正在尝试将 Spring 引导与 jawr 集成,但出现以下错误:

n.j.w.r.b.r.AbstractBundleLinkRenderer : No bundle found for path : /bundles/dependency.css n.j.w.r.b.r.AbstractBundleLinkRenderer : No bundle found for path : /bundles/app.css n.j.w.r.b.r.AbstractBundleLinkRenderer : No bundle found for path : /bundles/ie-support.js

我的静态文件夹中有这些文件:

发生了什么事?

我的 index.ftl 文件。

您是否检查过您的捆绑包是否正在您的临时目录中生成。 windows 中的示例您会发现临时目录通常位于:

C:\Users\<username>\AppData\Local\Temp\tomcat.<random numbers>.8080\work\Tomcat\localhost\<context path>\jawrTmp

我发现,因为它是您构建的 jar 而不是带有 webapp 目录的旧 mvc war 文件,您需要使用类路径生成器:

https://j-a-w-r.github.io/docs/generators.html

The prefix is a key you will specify when implementing the Generator, and the path is a string which will have different meaning depending on your generator’s functionality. Also, you have params in parentheses and in brackets (both of which are optional), that further help in parameterizing the mappings. A simple mapping example, with no params, is as follows:

jawr.js.bundle.one.mappings=jar:net/jawr/cpscript.js

不过要小心,因为我个人没有注意到这个金块:

Unlike the normal mapping, this way of referring to resources does not yet allow wildcards (i.e.: jar:/com/mycompany/myapp/** would not work).

因为它不会递归地遍历目录,所以我不得不手动将它们全部添加到 jawr.properties。

一些附加信息

在此之后,我注意到 .sorting 文件将附加到包的内容中(出于某些有趣的原因,我无法弄清楚为什么某些映射会与 /jar:<mapping>; MinJS 处理器完全失去了理智。

所以我个人找不到解决这个问题的方法,所以我构建了一个自定义的后处理器和预处理器。预处理器遍历每个映射并将 /jar:<mapping> 值固定为 jar:<mapping> 并使用 .sorting 文件的内容填充静态列表。

PostProcessor 然后从包的内容中删除对该静态列表中包含的值的任何引用(很好地解决了该问题)。仍然有一个问题,我可以 http 到前缀为 context-path/jsb/bundles 的包,但我的应用程序仍然没有启动 /bundles 所以不确定我自己是否有问题。

简而言之,因为您有一个 jar,所以您必须通过类路径而不是通过 servlet 加载内容(我相信默认情况下它正在搜索。)

希望这对您有所帮助,如果您设法使其全部正常运行,请在此处分享,因为 spring-boot jars 和 jawr 的文档很少。