我正在关注这个documentation它给出了以下示例:
<servlet>
<servlet-name>SwaggerBootstrap</servlet-name>
<servlet-class>io.swagger.api.util.Bootstrap</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
但是,我找不到获取 io.swagger.api.util.Bootstrap
类的位置。
我在 Swagger GitHub 存储库中看不到这个,也找不到任何 Maven 模块。
我在哪里可以找到这个?
最佳答案
io.swagger.api.util.Bootstrap
只是一个sample servlet。你必须在你的应用程序中创建一个类似 create a BeanConfig
的 servlet并设置 Swagger。
servlet 类名 (Bootstrap
) 和包 (io.swagger.api.util
) 只是示例。给类起你想要的名字,然后把它放在你想要的包里。
来自documentation :
Using a Servlet
A sample servlet would be:
package io.swagger.api.util; import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; public class Bootstrap extends HttpServlet { @Override public void init(ServletConfig config) throws ServletException { super.init(config); BeanConfig beanConfig = new BeanConfig(); beanConfig.setVersion("1.0.2"); beanConfig.setSchemes(new String[]{"http"}); beanConfig.setHost("localhost:8002"); beanConfig.setBasePath("/api"); beanConfig.setResourcePackage("io.swagger.resources"); beanConfig.setScan(true); } }
And adding the following snippet to the web.xml will ensure the initialization of Swagger:
<servlet> <servlet-name>SwaggerBootstrap</servlet-name> <servlet-class>io.swagger.api.util.Bootstrap</servlet-class> <load-on-startup>2</load-on-startup> </servlet>
There's no need for a URL mapping for this servlet as it is only used to initialize the application.
You are done with this guide! You should now be able to access the Swagger definition at
/swagger.json
and/swagger.yaml
at the context root of your application.
关于java - 从哪里获得 Swagger 的 Bootstrap servlet?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33694422/