当前位置:首页 >> 核电技术聚变聚能设备 >> 【Swagger】只需要三步,就可以让你的项目实现Swagger在线文档,实时浏览,修改展示,旭日150

【Swagger】只需要三步,就可以让你的项目实现Swagger在线文档,实时浏览,修改展示,旭日150

cpugpu芯片开发光刻机 核电技术聚变聚能设备 1
文件名:【Swagger】只需要三步,就可以让你的项目实现Swagger在线文档,实时浏览,修改展示,旭日150 【Swagger】只需要三步,就可以让你的项目实现Swagger在线文档,实时浏览,修改展示

目录

1. pom.xml文件中添加Swagger的jar包

2. 配置Swagger 

3. 项目启动中加入Swagger注解的开关,启动Swagger功能

4. 启动项目,查看效果


 

Swagger 的功能这里就不多说明了,相信大家都懂的,好奇多问一句,大家有知道其他类似Swagger的替代品吗?欢迎留言一起交流!!

只需要三步,快速启用Swagger功能,让你的项目实现Swagger在线文档,实时浏览,修改展示

1. pom.xml文件中添加Swagger的jar包

2. 配置Swagger 

3. 项目启动中加入Swagger注解的开关,启动Swagger功能

具体如下:

1. pom.xml文件中添加Swagger的jar包

我这里使用的spring boot是2.1.4的版本

<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.1.4.RELEASE</version></parent>

Swagger 依赖:

<!-- swagger --><dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger2</artifactId><version>2.9.1</version></dependency><!-- swagger-ui --><dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger-ui</artifactId><version>2.10.0</version></dependency><!-- 解决 Illegal DefaultValue null for parameter type integer 异常 --><dependency><groupId>io.swagger</groupId><artifactId>swagger-annotations</artifactId><version>1.5.21</version></dependency><dependency><groupId>io.swagger</groupId><artifactId>swagger-models</artifactId><version>1.5.21</version></dependency>

2. 配置Swagger  @Configuration@EnableSwagger2public class Swagger2 {@Beanpublic Docket createRestApi() {return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select().apis(RequestHandlerSelectors.basePackage("com.gcc.account")).paths(PathSelectors.any()).build();}private ApiInfo apiInfo() {return new ApiInfoBuilder().title("GCC Account API").contact(new Contact("gcc", "", "")).version("1.0").description("API描述").build();}}

3. 项目启动中加入Swagger注解的开关,启动Swagger功能 @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})@EnableSwagger2public class AccountApplication {public static void main(String[] args) {SpringApplication.run(AccountApplication.class, args);}}

4. 启动项目,查看效果

访问地址: http://localhost:8011/gccaccount/swagger-ui.html#/

 

协助本站SEO优化一下,谢谢!
关键词不能为空
同类推荐
«    2025年12月    »
1234567
891011121314
15161718192021
22232425262728
293031
控制面板
您好,欢迎到访网站!
  查看权限
网站分类
搜索
最新留言
文章归档
网站收藏
友情链接