提交 eb3072e9 authored 作者: LJJ's avatar LJJ

添加swagger、配置统一启动项

上级 162a312c
......@@ -4,7 +4,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ds</artifactId>
<groupId>com.zjty</groupId>
<groupId>com.zjty.ds</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -4,7 +4,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ds</artifactId>
<groupId>com.zjty</groupId>
<groupId>com.zjty.ds</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......@@ -12,4 +12,53 @@
<artifactId>ds-misc</artifactId>
<properties>
<swagger.version>2.9.0</swagger.version>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>com.github.caspar-chen</groupId>
<artifactId>swagger-ui-layer</artifactId>
<version>0.0.4</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-bean-validators</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>io.github.swagger2markup</groupId>
<artifactId>swagger2markup</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.zjty.ds.misc;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
* @author LJJ cnljj1995@gmail.com
* on 2020-02-26
*/
@SpringBootApplication
@EnableSwagger2
public class MiscApplcaiton {
}
package com.zjty.ds.misc.config;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* fusion-platform. swagger2 autoDocument interface for {@link Swagger2Config}
*
* @author : Matrix [xhyrzldf@gmail.com]
* 19-1-10 .
*/
@Target({TYPE, ANNOTATION_TYPE})
@Retention(RUNTIME)
@Documented
public @interface AutoDocument {
String value() default "";
}
package com.zjty.ds.misc.config;
import com.google.common.collect.Sets;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
* fusion-platform.
*
* @author : Matrix [xhyrzldf@gmail.com]
* 19-1-10 .
*/
@Configuration
@EnableSwagger2
public class Swagger2Config {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.produces(Sets.newHashSet("application/json"))
.consumes(Sets.newHashSet("application/json"))
.protocols(Sets.newHashSet("http"))
.apiInfo(apiInfo())
.forCodeGeneration(true)
.useDefaultResponseMessages(true)
// .globalResponseMessage(RequestMethod.GET, getResMsg())
.select()
// 指定controller存放的目录路径
.apis(RequestHandlerSelectors.withClassAnnotation(AutoDocument.class))
.paths(PathSelectors.any())
.build();
// .apiInfo(apiInfo())
// .securitySchemes(Collections.singletonList(securityScheme()))
// .securityContexts(Collections.singletonList(securityContext()));
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
// 文档标题
.title("XXX项目的API对接文档")
// 文档描述
.description("XXX项目的接口文档与测试页面")
.termsOfServiceUrl("http://192.168.1.1:8080/ty-note/ty-note-blackend.git")
.version("v 0.1.0")
.contact(new Contact("xxx", "http://localhost:8080/xxx", "ty@example.com"))
.build();
}
}
# dir files
/target/
/log/*
/file
/files
# Compiled class file
*.class
# Log file
*.log
.log
**/.log
# publisher file
schemes.json
# BlueJ files
*.ctxt
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
# other files
!.mvn/wrapper/maven-wrapper.jar
*#
*.iml
*.ipr
*.iws
*.jar
*.sw?
*~
.#*
.*.md.html
.DS_Store
.classpath
.factorypath
.gradle
.idea
.metadata
.project
.recommenders
.settings
.springBeans
/build
/code
MANIFEST.MF
_site/
activemq-data
bin
build
build.log
dependency-reduced-pom.xml
dump.rdb
interpolated*.xml
lib/
manifest.yml
overridedb.*
settings.xml
target
transaction-logs
.flattened-pom.xml
secrets.yml
.gradletasknamecache
.sts4-cache
\ No newline at end of file
......@@ -4,7 +4,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ds</artifactId>
<groupId>com.zjty</groupId>
<groupId>com.zjty.ds</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -4,12 +4,58 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ds</artifactId>
<groupId>com.zjty</groupId>
<groupId>com.zjty.ds</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ds-union</artifactId>
<dependencies>
<dependency>
<groupId>com.zjty.ds</groupId>
<artifactId>ds-misc</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!--打包插件-->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
<!--跳过测试插件-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<skipTests>true</skipTests> <!--默认关掉单元测试 -->
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package com.zjty.ds.union;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* 项目启动类
*
* @author LJJ cnljj1995@gmail.com
* on 2020-02-26
*/
@SpringBootApplication(scanBasePackages = {
"com.zjty.ds.misc",
"com.zjty.ds.union"
})
public class UnionApplication {
public static void main(String[] args) {
SpringApplication.run(UnionApplication.class, args);
}
}
......@@ -18,7 +18,7 @@
</parent>
<groupId>com.zjty</groupId>
<groupId>com.zjty.ds</groupId>
<artifactId>ds</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论