av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術文章
文章詳情頁

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

瀏覽:38日期: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的一些基本的內容,比如掃描的包等等@Beanpublic Docket createRestApi() {return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()// 為當前包路徑.apis(RequestHandlerSelectors.basePackage('com.oauth.controller')).paths(PathSelectors.any()).build();}private ApiInfo apiInfo() {return new ApiInfoBuilder()// 頁面標題.title('Swagger2')// 創建人信息.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 這里是設置是否啟動 本地和測試環境為true 正式環境為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 這里設置為false

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

總結

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

標簽: Spring
相關文章:
主站蜘蛛池模板: 九九综合 | 国产99久久精品一区二区永久免费 | 成人国产午夜在线观看 | 久久综合狠狠综合久久综合88 | 天天爽天天操 | 欧美综合一区二区 | 日本黄色片免费在线观看 | 久日精品 | 久久99精品久久久97夜夜嗨 | 久久久久国 | 中文字幕国产在线 | 第四色影音先锋 | 日韩视频在线免费观看 | 国产免费观看视频 | 国产91久久久久久 | 欧美涩涩网 | 国产精品一区久久久 | 男女性毛片| 怡红院怡春院一级毛片 | 国产高清在线 | 国产欧美精品区一区二区三区 | 欧美精品久久久 | 黄网站涩免费蜜桃网站 | 国产欧美在线 | 中文字幕中文字幕 | 免费一级片 | 久久久久电影 | 成人国产午夜在线观看 | 色婷婷国产精品综合在线观看 | 亚洲国产欧美一区二区三区久久 | 91免费电影| 国产一级在线 | 国产精品久久久久久久毛片 | 华人黄网站大全 | 男人天堂久久 | 视频1区2区 | 欧美成人一区二区 | 日韩成年人视频在线 | 欧美视频二区 | 中文字幕一区二区三区不卡 | 亚洲精品一区二区三区四区高清 |