gpt4 book ai didi

java - Dropwizard,为同一 URI 提供两种 Assets

转载 作者:行者123 更新时间:2023-11-28 08:31:15 27 4
gpt4 key购买 nike

我如何在 Dropwizard 中为同一个 URI 提供两个 Assets 文件夹。当前仅提供第一个,当 URI 使用相同的名称时。

我正在使用(在我的主应用程序类中)注册 AssetsBundle:

public void initialize(Bootstrap<DummyFrontendConfiguration> bootstrap) {
bootstrap.addBundle(new AssetsBundle("/assets1", "/public", null, "assets1"));
bootstrap.addBundle(new AssetsBundle("/assets2", "/public", null, "assets2"));
bootstrap.addBundle(new ViewBundle());
}

assets1 中的 css 文件(main.css):

h2{
color: red;
}

assets2中的css文件(main2.css):

h4{
color: green;
}

在 html 模板头中:

<link rel="stylesheet" type="text/css" href="public/stylesheets/main.css">
<link rel="stylesheet" type="text/css" href="public/stylesheets/main2.css">

在 html 模板正文中:

<h2>This should be red</h2>
<h4>This should be green</h4>

不幸的是,在 html 页面呈现期间无法加载第二个 css 文件 (main2.css)(404 - 未找到),有什么想法吗?

最佳答案

assets 模块并非设计为以这种方式运行。在引擎盖下它正在调用:

environment.servlets().addServlet(assetsName, createServlet()).addMapping(uriPath + '*');

两个 servlet 不能映射到同一路径。您可以通过将其中一个“公共(public)”映射切换为另一条路径(例如“public2”)来解决此问题。

如果您确实需要保持资源完全独立,您可能需要考虑在构建中引入另一个步骤(通过 maven 或 ant),将 Assets 合并到单个目录结构中以进行部署。

关于java - Dropwizard,为同一 URI 提供两种 Assets ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28260756/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com