1
0
mirror of https://github.com/jht5945/springbootswaggersample.git synced 2025-12-27 10:00:03 +08:00

init commit

This commit is contained in:
2019-09-13 14:33:40 +08:00
parent c7aeafaa1f
commit 2993820011
6 changed files with 168 additions and 0 deletions

3
.gitignore vendored
View File

@@ -19,5 +19,8 @@
*.tar.gz
*.rar
.gradle/
build/
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

79
build.gradle Normal file
View File

@@ -0,0 +1,79 @@
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
def buildJSON = new groovy.json.JsonSlurper().parseText(new File("build.json").text)
def baseProjectName = buildJSON?.project?.name ?: '__project_name__';
def shellCommandName = baseProjectName
def eclipseProjectName = baseProjectName
def eclipseProjectComment = buildJSON?.project?.comment ?: '__project_name_comment__'
def jarManifestMainClass = buildJSON?.project?.main ?: 'me.hatter.sample.SampleMain'
archivesBaseName = buildJSON?.project?.archiveName ?: baseProjectName
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
// mavenCentral()
maven() { url 'https://maven.aliyun.com/repository/central' }
}
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
// '-x test' skip unit test
defaultTasks 'build'
buildscript {
repositories {
mavenLocal()
mavenCentral()
jcenter()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.11.RELEASE")
}
}
apply plugin: 'org.springframework.boot'
springBoot {
mainClass = jarManifestMainClass
}
dependencies {
compile files(fileTree(dir: 'lib', includes: ['*.jar'], excludes: ['*-sources.jar', '*-javadoc.jar']))
if (buildJSON.repo != null && buildJSON.repo.dependencies != null) {
buildJSON.repo.dependencies.each {
compile("${it}")
}
}
}
eclipse {
project {
name = eclipseProjectName
comment = eclipseProjectComment
}
classpath {
defaultOutputDir = file('classes')
downloadSources = true
file {
whenMerged { classpath ->
classpath.entries.findAll { it.kind=='lib' }.each {
if ((it.path != null) && (it.sourcePath == null) && file(it.path.replace(".jar", "-sources.jar")).exists()) {
it.sourcePath = getFileReferenceFactory().fromPath(it.path.replace(".jar", "-sources.jar"))
}
}
}
}
}
}
eclipseJdt << {
File f = file('.settings/org.eclipse.core.resources.prefs')
f.write('eclipse.preferences.version=1\n')
f.append('encoding/<project>=utf-8')
}

20
build.json Normal file
View File

@@ -0,0 +1,20 @@
{
"project": {
"name": "springbootswaggersample",
"main": "me.hatter.sample.springbootswagger.Application",
"archiveName": "sprintbootswaggersample"
},
"java": "1.8",
"builder": {
"name": "gradle",
"version": "3.1"
},
"repo": {
"dependencies": [
"org.springframework.boot:spring-boot-starter:1.3.2.RELEASE",
"org.springframework.boot:spring-boot-starter-web:1.3.2.RELEASE",
"io.springfox:springfox-swagger2:2.2.2",
"io.springfox:springfox-swagger-ui:2.2.2"
]
}
}

View File

@@ -0,0 +1,12 @@
package me.hatter.sample.springbootswagger;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

View File

@@ -0,0 +1,37 @@
package me.hatter.sample.springbootswagger;
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.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class Swagger2 {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("me.hatter.sample.springbootswagger.web"))
.paths(PathSelectors.any())
.build();
}
ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Springboot swagger sample")
.description("Tthe Springboot swagger sample")
.termsOfServiceUrl("https://hatter.ink/")
.contact("Hatter")
.version("1.0.0")
.build();
}
}

View File

@@ -0,0 +1,17 @@
package me.hatter.sample.springbootswagger.web;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/sample")
public class SampleController {
@ApiOperation(value = "Hello", notes = "Say Hello World!")
@RequestMapping(value = "", method = RequestMethod.GET)
public String hello() {
return "Hello world!";
}
}