代码编织梦想

1.maven导入swagger包

<dependency>

<groupId>io.springfox</groupId>

<artifactId>springfox-swagger2</artifactId>

<version>2.9.2</version>

</dependency>

<dependency>

<groupId>io.springfox</groupId>

<artifactId>springfox-swagger-ui</artifactId>

<version>2.9.2</version>

</dependency>

<dependency>

<groupId>net.minidev</groupId>

<artifactId>json-smart</artifactId>

</dependency>

2.配置swagger配置类

@Configuration

@EnableSwagger2

public class Swagger2Config {

private ApiInfo apiInfo(){

ApiInfoBuilder apiInfoBuilder = new ApiInfoBuilder();

apiInfoBuilder.title("Spring Boot Day 4 API 接口文档")

.version("1.0")

.description("演示授课内容使用");

return apiInfoBuilder.build();

}

@Bean

public Docket createRestApi() {

Docket docket = new Docket(DocumentationType.SWAGGER_2);

docket.apiInfo(apiInfo()).select() .apis(RequestHandlerSelectors.basePackage("com.wx.springbootday4.controller"))

//为有@Api注解的Controller生成API文档

// .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))

//为有@ApiOperation注解的方法生成API文档

// .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))

.paths(PathSelectors.any())

.build().directModelSubstitute(Timestamp.class,Long.class);

return docket;

}

}

3.配置application.yml文件

spring:

mvc:

pathmatch:

matching-strategy: ant_path_matcher

4.通过http://localhost:8080/swagger-ui.html,通过地址方法访问文档

9fac007f7d91a2d1e5bcd7a61ed230ce.png

5.按照以上整合Swagger如何报

org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException

可能是SpringBoot与Swagger版本不兼容,如果SpringBoot版本在2.5.6以上Swagger应该使用3.0.0的版本,SpringBoot版本在2.5.6以下Swagger可以使用2.9.2版本,上面整合的Swagger版本是2.9.2,SpringBoot是2.5.6版本

  1. SpringBoot2.7.9版本整合Swagger3.0.0版本

  1. maven导入swagger包

<dependency>

<groupId>io.springfox</groupId>

<artifactId>springfox-boot-starter</artifactId>

<version>3.0.0</version>

</dependency>

  1. 配置swagger配置类

@Configuration

public class Swagger3Config {

private ApiInfo apiInfo(){

ApiInfoBuilder apiInfoBuilder = new ApiInfoBuilder();

apiInfoBuilder.title("Spring Boot Day 4 API 接口文档")

.version("1.0")

.description("演示授课内容使用");

return apiInfoBuilder.build();

}

@Bean

public Docket createRestApi() {

Docket docket = new Docket(DocumentationType.OAS_30);

docket.apiInfo(apiInfo()).select() .apis(RequestHandlerSelectors.basePackage("com.dyh"))

//为有@Api注解的Controller生成API文档

// .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))

//为有@ApiOperation注解的方法生成API文档

// .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))

.paths(PathSelectors.any());

// .build().directModelSubstitute(Timestamp.class,Long.class);

return docket;

}

}

3.配置application.yml文件

spring:

mvc:

pathmatch:

matching-strategy: ant_path_matcher

4.通过http://localhost:8080/swagger-ui/index.html,通过地址方法访问文档

21aff1fafa68af030fc4126dab4869a7.png

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_45834289/article/details/129665921

springboot整合swagger_大磊程序员(轻大)的博客-爱代码爱编程

1.在pom中引入swagger依赖 <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> </dependency> <depen

springboot整合swagger_博客小周的博客-爱代码爱编程

一、引入相关依赖 <!-- 图像化依赖 --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>

【spring高级49讲】-爱代码爱编程

Spring高级49讲 Spring是整个Java体系最核心的框架,没有之一面试必备技术、思想提升 一.容器和Bean 第1讲.BeanFactory和ApplicationContext 1.1.Bean

jpa更新部分字段方式-爱代码爱编程

JPA相较于Mybatis来说,对于增、删、查功能倒是相差不大,但是就更改这一块,个人感觉还是mybatis方便一些,因此这里总结下自己的JPA更新字段的方式。 JPA更新最大的问题是没有可以直接使用的函数,目前只能依托于

javaee简单示例——基于注解的aop实现-爱代码爱编程

简单介绍: 之前我们介绍了关于XML的面向切面的编程,通过配置文件的方法,在不修改源代码的情况下完成了对已有方法的增强 除了基于XML配置文件的方式,我们还可以使用更简单的,基于注解的方式。 每一次,我们在使用面向切面的注解的时候,我们都要明确三个问题,插什么?插谁?插在哪? 这三个问题也就对应了我们面向切面中的切面,增强,切入点,关系。带着这样的问题

实验5---spring ioc-注解实现-爱代码爱编程

Spring IoC-注解实现 一、实验目的及任务 通过该实验掌握利用Spring 注解方式实现控制反转IoC(依赖注入),掌握Spring常用注解的含义和用法。 二、实验结果 自己编写的代码和配置信息,包括applicationContext.xml,UserServiceImpl,UserDaoImpl等与注解相关的代码。

springboot集成quartz实现定时任务(可修改cron表达式和传入参数)-爱代码爱编程

第一步创建SpringBoot项目的过程我就不在演示了!自己找找教程吧! 第二步,导入依赖: <dependencies> <dependency> <groupId>org.springframework.boot</groupId> &