我在基于java spring的应用程序中运行springfox v2.7.0。我们在web.xml中配置了3个调度服务器:
1)常见的springmvc servlet [Active]
<servlet>
<servlet-name>springmvc-v1</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextClass</param-name>
<param-value>
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
</param-value>
</init-param>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
com.test.mywebservices.v1.config.WebConfig
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
3)springmvc-v2 servlet [Active]: for this I am implimenting swagger.
<servlet>
<servlet-name>springmvc-v2</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextClass</param-name>
<param-value>
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
</param-value>
</init-param>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
com.test.mywebservices.v2.config.WebConfig
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc-v2</servlet-name>
<url-pattern>/v2/*</url-pattern>
</servlet-mapping>
2)springmvc-v1 servlet [inactive]:通过在web.xml中注释掉它而不使用它来禁用它。
@FormEncodedUrl
它工作正常,我可以从这里获得swagger资源: https://localhost:9002/mywebservices/v2/swagger-resources
我可以从这里查看api: https://localhost:9002/mywebservices/v2/v2/api-docs
可以从这里访问Swagger-UI: https://localhost:9002/mywebservices/swagger-ui.html
问题是当我加载https://localhost:9002/mywebservices/swagger-ui.html页面时,它试图从这里访问swagger-resources: https://localhost:9002/mywebservices/swagger-resources
它们不可用。但它可以在https://localhost:9002/mywebservices/v2/swagger-resources
获得我如何解决这个问题,以便swagger-ui.html: 我认为Swagger-ui.html应该在https://localhost:9002/mywebservices/v2/swagger-ui.html提供,以便springfox.js获得正确的baseUrl。
https://localhost:9002/mywebservices/swagger-ui.html&gt;&gt;&gt;页面加载但弹出窗口输入基本URL
https://localhost:9002/mywebservices/swagger-resources/configuration/ui&gt;&gt;&gt;给出404弹出窗口
https://localhost:9002/mywebservices/webjars/springfox-swagger-ui/springfox.js&gt;&gt;&gt;能够访问。这工作正常。
请建议解决方案。 提前谢谢。
答案 0 :(得分:1)
我遇到了同样的问题。
解决方案是映射到应用程序的MVC配置,手动由Controller管理swagger-common.jar中存在的swagger-resources的映射。软件包值为“ springfox.documentation.swagger.web” 。该配置(取决于您的应用)应与以下所示类似:
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = { ApplicationPackages.REST_CONTROLLER_BASE_PACKAGE,
"springfox.documentation.swagger.web" })
public class MvcConfig extends WebMvcConfigurerAdapter {
}