优化Springmvc文档显示

pull/1/head
tanghc 5 years ago
parent 94d9b0da90
commit 75d5d9b101
  1. 12
      sop-example/sop-springmvc/pom.xml
  2. 21
      sop-example/sop-springmvc/src/main/java/com/gitee/app/config/Swagger2.java
  3. 6
      sop-example/sop-springmvc/src/main/java/com/gitee/app/controller/HomeController.java
  4. 5
      sop-example/sop-springmvc/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
  5. 23
      sop-example/sop-springmvc/src/main/webapp/WEB-INF/web.xml
  6. 4
      sop-website/src/main/java/com/gitee/sop/websiteserver/listener/ServiceDocListener.java

@ -91,6 +91,18 @@
<version>1.2.17</version>
</dependency>
<!-- swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.9.5</version>
</dependency>
<!-- @Inject -->
<dependency>

@ -0,0 +1,21 @@
package com.gitee.app.config;
import com.gitee.sop.servercommon.swagger.SwaggerSupport;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
* 开启文档本地微服务文档地址http://localhost:2222/doc.html
* http://ip:port/v2/api-docs
*/
@EnableSwagger2
public class Swagger2 extends SwaggerSupport {
@Override
protected String getDocTitle() {
return "MVC_API";
}
@Override
protected boolean swaggerAccessProtected() {
return false;
}
}

@ -1,7 +1,9 @@
package com.gitee.app;
package com.gitee.app.controller;
import com.gitee.app.model.Goods;
import com.gitee.sop.servercommon.annotation.ApiMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
@ -18,6 +20,7 @@ import java.util.Locale;
/**
* Handles requests for the application home page.
*/
@Api(tags = "MVC接口")
@Controller
public class HomeController {
@ -41,6 +44,7 @@ public class HomeController {
}
@ApiOperation(value="获取商品", notes = "获取商品说明")
@ApiMapping(value = "springmvc.goods.get")
@ResponseBody
public Goods getGoods(Goods param) {

@ -34,6 +34,11 @@
</mvc:annotation-driven>
<bean class="com.gitee.app.config.OpenServiceConfig"/>
<!-- swagger2 配置 -->
<mvc:resources location="classpath:/META-INF/resources/" mapping="doc.html"/>
<mvc:resources location="classpath:/META-INF/resources/webjars/" mapping="/webjars/**"/>
<bean class="com.gitee.app.config.Swagger2"/>
<!-- 接入SOP配置 end -->
</beans>

@ -30,6 +30,29 @@
<load-on-startup>1</load-on-startup>
</servlet>
<!-- 配置swagger-bootstrap-ui的url请求路径-->
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/v2/api-docs</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/swagger-resources</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/swagger-resources/configuration/ui</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/swagger-resources/configuration/security</url-pattern>
</servlet-mapping>
<!--此接口地址为SwaggerBootstrapUi提供的增强地址,如果不使用增强功能,可排除此配置-->
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/v2/api-docs-ext</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>

@ -1,6 +1,7 @@
package com.gitee.sop.websiteserver.listener;
import com.gitee.sop.gatewaycommon.bean.InstanceDefinition;
import com.gitee.sop.gatewaycommon.bean.SopConstants;
import com.gitee.sop.gatewaycommon.route.BaseServiceListener;
import com.gitee.sop.websiteserver.manager.DocManager;
import lombok.extern.slf4j.Slf4j;
@ -45,6 +46,7 @@ public class ServiceDocListener extends BaseServiceListener {
private static String getRouteRequestUrl(InstanceDefinition instance) {
String query = buildQuery(SECRET);
return "http://" + instance.getIp() + ":" + instance.getPort() + "/v2/api-docs" + query;
String contextPath = instance.getMetadata().getOrDefault(SopConstants.METADATA_SERVER_CONTEXT_PATH, "");
return "http://" + instance.getIp() + ":" + instance.getPort() + contextPath + "/v2/api-docs" + query;
}
}

Loading…
Cancel
Save