国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

spring boot-2.1.16整合swagger-2.9.2 含yml配置文件的代碼詳解

瀏覽:35日期:2023-08-22 18:00:26

java代碼

package com.oauth.util;import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;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;@Configuration@EnableSwagger2//是否開啟swagger@ConditionalOnProperty(name = 'swagger.enable', havingValue = 'true')public class Swagger2 {// swagger2的配置文件,這里可以配置swagger2的一些基本的內(nèi)容,比如掃描的包等等@Beanpublic Docket createRestApi() {return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()// 為當(dāng)前包路徑.apis(RequestHandlerSelectors.basePackage('com.oauth.controller')).paths(PathSelectors.any()).build();}private ApiInfo apiInfo() {return new ApiInfoBuilder()// 頁面標(biāo)題.title('Swagger2')// 創(chuàng)建人信息.contact(new Contact('scy', '666', '888'))// 版本號.version('1.0')// 描述.description('API 描述').build();}}

yml文件

server: port: 8587spring: application: name: auth eureka: instance: prefer-ip-address: true client: service-url: defaultZone: http://localhost:8090/eureka/ swagger: enable: true

swagger:enable: true 這里是設(shè)置是否啟動(dòng) 本地和測試環(huán)境為true 正式環(huán)境為false

controller

package com.oauth.controller;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;import io.swagger.annotations.Api;import io.swagger.annotations.ApiOperation;@RestController@RequestMapping('api')@Api(value = '測試接口', tags = 'IndexController')public class IndexController {@ApiOperation(value = 'hello')@GetMapping('hello')public String hello() {return 'Hello World';}@ApiOperation(value = 'hello2')@GetMapping('api/hello')public String apiHello() {return 'Hello World';}}

打開swagger頁面 localhost:端口號/swagger-ui.html

spring boot-2.1.16整合swagger-2.9.2 含yml配置文件的代碼詳解

如果swagger:enable: false 這里設(shè)置為false

spring boot-2.1.16整合swagger-2.9.2 含yml配置文件的代碼詳解

總結(jié)

到此這篇關(guān)于spring boot-2.1.16整合swagger-2.9.2 含yml配置文件的文章就介紹到這了,更多相關(guān)spring boot整合swagger內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 克拉玛依市| 南安市| 呼玛县| 梁平县| 保康县| 桂东县| 阿克| 大港区| 凤城市| 和平区| 丹寨县| 桑日县| 林州市| 牡丹江市| 虞城县| 满洲里市| 蓝田县| 晋江市| 潞西市| 阿克| 淮阳县| 萨迦县| 时尚| 赤城县| 浦江县| 桃江县| 遂宁市| 攀枝花市| 阳原县| 永靖县| 丹寨县| 乳山市| 托克托县| 吐鲁番市| 资阳市| 嵊泗县| 大姚县| 灵璧县| 温泉县| 连云港市| 久治县|