瀏覽代碼

提交到Dev分支

chenweida 7 年之前
父節點
當前提交
7ccf23e31c

+ 22 - 1
common-lib-parent-pom/pom.xml

@ -6,11 +6,32 @@
    <groupId>com.yihu</groupId>
    <artifactId>common-lib-parent-pom</artifactId>
    <version>1.0-SNAPSHOT</version>
    <version>1.0.0</version>
    <packaging>pom</packaging>
    <modules>
        <module>../common/common-log</module>
        <module>../common/common-swagger</module>
    </modules>
    <properties>
        <version.swagger>2.4.0</version.swagger>
        <version.swagger-ui>2.4.0</version.swagger-ui>
    </properties>
    <dependencyManagement>
        <dependencies>
            <!--swagger ui start-->
            <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger2</artifactId>
                <version>${version.swagger}</version>
            </dependency>
            <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger-ui</artifactId>
                <version>${version.swagger-ui}</version>
            </dependency>
            <!--swagger ui end-->
        </dependencies>
    </dependencyManagement>
</project>

+ 17 - 1
common/common-swagger/pom.xml

@ -3,10 +3,26 @@
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.yihu</groupId>
        <artifactId>common-lib-parent-pom</artifactId>
        <version>1.0.0</version>
        <relativePath>../../common-lib-parent-pom/pom.xml</relativePath>
    </parent>
    <groupId>com.yihu</groupId>
    <artifactId>common-swagger</artifactId>
    <version>1.0-SNAPSHOT</version>
    <version>1.0.0</version>
    <dependencies>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
        </dependency>
    </dependencies>
</project>

+ 4 - 0
common/common-swagger/readme.MD

@ -0,0 +1,4 @@
swagger工具工程
需要用的微服务需要2步奏
    1 引入此工程
    2 修改swaggerConfig 配置 然后添加扫描的路径

+ 76 - 0
common/common-swagger/src/main/java/com/yihu/common/config/SwaggerConfig.java

@ -0,0 +1,76 @@
package com.yihu.common.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import static com.google.common.base.Predicates.or;
import static springfox.documentation.builders.PathSelectors.regex;
@Configuration
@EnableSwagger2
@ComponentScan("com.yihu.**.controller")
public class SwaggerConfig {
    public static final String LEGACY_API = "Legacy";
    public static final String PUBLIC_API = "Default";
    @Bean
    public Docket publicAPI() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName(PUBLIC_API)
                .useDefaultResponseMessages(false)
                .forCodeGeneration(true)
                .pathMapping("/")
                .select()
                .paths(or(regex("/api.*")))
                .build()
                .apiInfo(publicApiInfo());
    }
    @Bean
    public Docket legacyAPI(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName(LEGACY_API)
                .useDefaultResponseMessages(false)
                .forCodeGeneration(false)
                .pathMapping("/")
                .select()
                .paths(or(regex("/rest/v.*")))
                .build()
                .apiInfo(legacyApiInfo());
    }
    private ApiInfo legacyApiInfo() {
        ApiInfo apiInfo = new ApiInfo("基卫2.0API",
                "基卫2.0API(历史兼容接口),此部分API因为设计不规范,但已经发布,所以继续提供兼容。",
                "1.0",
                "No terms of service",
                "wenfujian@jkzl.com",
                "The Apache License, Version 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0.html"
        );
        return apiInfo;
    }
    private ApiInfo publicApiInfo() {
        ApiInfo apiInfo = new ApiInfo("基卫2.0API",
                "基卫2.0API,提供健康档案服务。",
                "1.0",
                "No terms of service",
                "wenfujian@jkzl.com",
                "The Apache License, Version 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0.html"
        );
        return apiInfo;
    }
}

+ 1 - 1
readme.MD

@ -1,8 +1,8 @@
项目结构
     common    公共的一些配置
        common-log   日志工程
        common-swagger   swagger工程
     svr    业务微服务  
        svr-user 用户微服务
     svr-configuration    配置服务
     svr-discovery    发现服务
     common-lib-parent-pom    common公共工程的maven父pom

+ 1 - 5
svr-discovery/src/main/resources/application.yml

@ -4,7 +4,7 @@ server:
spring:
  cloud:
    config:
      enabled: false
      enabled: false    ##是否加入配置服务
eureka:
  client:
@ -23,10 +23,6 @@ info:
spring:
  profiles: dev
---
spring:
  profiles: alpha
---
spring:
  profiles: test

+ 3 - 0
svr-lib-parent-pom/pom.xml

@ -24,6 +24,9 @@
        <module>../svr-configuration</module> <!--配置服务-->
        <module>../svr-discovery</module><!--发现服务-->
        <!--业务微服务-->
        <module>../svr/svr-user</module><!--用户微服务-->
    </modules>
    <properties>

+ 7 - 7
common/common-log/pom.xml

@ -3,15 +3,15 @@
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.yihu</groupId>
        <artifactId>svr-lib-parent-pom</artifactId>
        <version>1.0.0</version>
        <relativePath>../../svr-lib-parent-pom/pom.xml</relativePath>
    </parent>
    <groupId>com.yihu</groupId>
    <artifactId>common-log</artifactId>
    <artifactId>svr-user</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
    </properties>
    <dependencies>
    </dependencies>
</project>