我正在使用Camel Jetty作为REST组件。对于码头,您只需添加一个额外的ResourceHandler来处理SwaggerUI资源。以下使用Spring xml语言配置REST:
<restConfiguration component="jetty" host="{{rest_hostname}}" port="{{rest_listen_port}}"
bindingMode="off" apiContextPath="api-docs" apiContextListing="true"
enableCORS="true">
<!--ResourceHandler to handle Swagger UI contents on the jetty-->
<endpointProperty key="handlers" value="swaggerUIHandler"/>
......
......
</restConfiguration>
我在webjars提供的jar中使用swaggerUI。配置处理器豆:
<bean id="swaggerUIHandler" class="com.yifanwu.examples.camel.JettyResourceHandlerFactory" factory-method="buildResourceHandler">
<!--your resource path is just "swagger" assuming it is on the classpath-->
<constructor-arg name="resourcePath" value="META-INF/resources/webjars"/>
</bean>
bean工厂:
public class JettyResourceHandlerFactory {
public static ResourceHandler buildResourceHandler(String resourcePath) throws Exception {
ResourceHandler rh = new ResourceHandler();
rh.setResourceBase(JettyResourceHandlerFactory.class.getClassLoader()
.getResource(resourcePath)
.toURI().toString());
return rh;
}
}
完整的示例在这里:github
您使用的web.xml文件?如果是这样,你可以请张贴吗? – Khaled
no web.xml我正在使用骆驼休息路线 – McQueen
我正在使用骆驼来整合Swagger。我下载了重命名为swagger的dist文件夹并更新了index.html,但我无法通过我的应用程序端口访问它:http:// localhost:$ { port}/$ { contextPath}/swagger/index。html 但是如果我输入http:// localhost:$ { port}/api-doc,我会得到swagger json dump。 我可以访问index.html,如果转到该文件并用浏览器手动打开它。如何使用我的应用程序端口访问index.html? http:// localhost:$ { port}/$ { contextPath} /swagger/index.html – McQueen