【发布时间】:2017-05-21 20:38:55
【问题描述】:
不久前我在我的 Dropwizard 服务中添加了 swagger,它运行良好。
但是现在我想添加一个简单的 html 页面并配置资源路径以提供来自 /assets 的内容,它破坏了招摇和 api
404 回复
这是我的代码
public class NumericodeApplication extends Application<NumericodeConfiguration> {
public static void main(final String[] args) throws Exception {
new NumericodeApplication().run(args);
}
@Override
public String getName() {
return "Numericode";
}
@Override
public void initialize(final Bootstrap<NumericodeConfiguration> bootstrap) {
bootstrap.addBundle(new SwaggerBundle<NumericodeConfiguration>() {
@Override
protected SwaggerBundleConfiguration getSwaggerBundleConfiguration(NumericodeConfiguration configuration) {
return configuration.swaggerBundleConfiguration;
}
});
bootstrap.addBundle(new AssetsBundle("/assets", "/", "index.html")); //added this
}
@Override
public void run(final NumericodeConfiguration configuration, final Environment environment) {
environment.jersey().register(new Controller());
environment.jersey().setUrlPattern("/swagger"); //tried this
environment.jersey().setUrlPattern("/api/*"); //added this
}
}
当我尝试删除两个 setUrlPattern() 方法调用时它会抱怨
多个servlet映射到路径/*: assets[mapped:JAVAX_API:null],io.dropwizard.jersey.setup.JerseyServletContainer-2e5b7fba[mapped:EMBEDDED:null]
但是,如果我删除资产包,Swagger 会再次正常工作吗?
我怎样才能让我的索引页和 swagger 在 Dropwizard/Jetty 上工作。
如果你能解释发生了什么,奖励积分!
【问题讨论】:
标签: java jersey dropwizard