Dropwizard 球衣集 URL 模式打破 Swagger 404?
Dropwizard Jersey set URL pattern breaking Swagger 404?
我不久前在我的 Dropwizard 服务中添加了 swagger,它运行良好。
但是现在我想添加一个简单的 html 页面并配置资源路径以提供来自 /assets
的内容,它已经破坏了 swagger 和 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() 方法调用时它会抱怨
Multiple servlets map to path /*: assets[mapped:JAVAX_API:null],io.dropwizard.jersey.setup.JerseyServletContainer-2e5b7fba[mapped:EMBEDDED:null]
但是,如果我删除资产包,Swagger 又可以正常工作了吗?
如何让我的索引页面和 swagger 在 Dropwizard/Jetty 上工作。
如果你能解释发生了什么,加分!
Either your application or your static assets can be served from the
root path, but not both. The latter is useful when using Dropwizard to
back a Javascript application. To enable it, move your application to
a sub-URL.
来源:http://www.dropwizard.io/1.1.0/docs/manual/core.html#serving-assets
bootstrap.addBundle(new AssetsBundle("/assets", "/", "index.html"));
此行试图将在 assets
资源目录中找到的资源装入 root
上下文路径。可能 Jersey 应用程序已经安装在那里。
您可以像下面这样在配置文件中添加 uriPrefix
swagger:
title: Test Application
resourcePackage: com.abc.xyz
uriPrefix: /api/v1
这将以/api/v1为基数url
我不久前在我的 Dropwizard 服务中添加了 swagger,它运行良好。
但是现在我想添加一个简单的 html 页面并配置资源路径以提供来自 /assets
的内容,它已经破坏了 swagger 和 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() 方法调用时它会抱怨
Multiple servlets map to path /*: assets[mapped:JAVAX_API:null],io.dropwizard.jersey.setup.JerseyServletContainer-2e5b7fba[mapped:EMBEDDED:null]
但是,如果我删除资产包,Swagger 又可以正常工作了吗?
如何让我的索引页面和 swagger 在 Dropwizard/Jetty 上工作。
如果你能解释发生了什么,加分!
Either your application or your static assets can be served from the root path, but not both. The latter is useful when using Dropwizard to back a Javascript application. To enable it, move your application to a sub-URL.
来源:http://www.dropwizard.io/1.1.0/docs/manual/core.html#serving-assets
bootstrap.addBundle(new AssetsBundle("/assets", "/", "index.html"));
此行试图将在 assets
资源目录中找到的资源装入 root
上下文路径。可能 Jersey 应用程序已经安装在那里。
您可以像下面这样在配置文件中添加 uriPrefix
swagger:
title: Test Application
resourcePackage: com.abc.xyz
uriPrefix: /api/v1
这将以/api/v1为基数url