springboot集成swagger教程

1、SpringBoot快速整合Swagger3.0 Swagger 是一款RESTFUL接口的文档在线自动生成+功能测试功能软件;Swagger的目标是为REST APIs 定义一个标准的,与语言无关的接口,使人和计算机在看不到源码或者看不到文档或者不能通过网络流量检测的情况下能发现和理解各种服务的功能。 阅读详情

第一步 引入pom

!!!如果springboot版本高的话可能会出现空指针异常,可以降低版本,如2.2.1

<!--swagger-->
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.7.0</version>
</dependency>
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>2.7.0</version>
</dependency>

第二步
在代码中加入相应的配置,新建config包,写入swaggerConfig配置类:


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
public class SwaggerConfig {

    /**
     * 创建API应用
     * apiInfo() 增加API相关信息
     * 通过select()函数返回一个ApiSelectorBuilder实例,用来控制哪些接口暴露给Swagger来展现,
     * 本例采用指定扫描的包路径来定义指定要建立API的目录。
     *
     * @return
     */
    @Bean
    public Docket restApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("标准接口")
                .apiInfo(apiInfo("Spring Boot中使用Swagger2构建RESTful APIs", "1.0"))
                .useDefaultResponseMessages(true)
                .forCodeGeneration(false)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.example.springboot.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 创建该API的基本信息(这些基本信息会展现在文档页面中)
     * 访问地址:http://ip:port/swagger-ui.html
     *
     * @return
     */
    private ApiInfo apiInfo(String title, String version) {
        return new ApiInfoBuilder()
                .title(title)
                .description("更多请关注: https://blog.youkuaiyun.com/Java_LiShu")
                .termsOfServiceUrl("https://blog.youkuaiyun.com/Java_LiShu")
                .contact(new Contact("java_xiaobai", "https://blog.youkuaiyun.com/Java_LiShu", "1812150233@qq.com"))
                .version(version)
                .build();
    }
}

2.使用swagger

http://ip:port/swagger-ui.html

​​​​​​​

spring boot 集成swagger 3.0 Swagger3在Swagger2的基础上进行了部分升级, 使用和Swagger2没有多少区别。一个重要的优化是依赖的引入,由之前的多个依赖变更为一个依赖,跟随springboot-starter风格,同时引入了新的开关注解 @EnableOpenApi 以代替@EnableSwagger2。一、Maven依赖二、application.yml文件配置三、添加配置。 阅读详情

相关推荐

Spring Boot 3项目集成Swagger3教程

欢迎来到我的小天地,这里是我记录技术点滴、分享学习心得的地方。??让我们一起在技术的道路上不断前行!??

m0_74823094的博客 1503

springboot2.6.7集成springfox3.0.0

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

ttyy1112的专栏 1208

【全网最新-首发】Springfox 3.0.0(包含springfox-swagger2-3.0.0)即OpenAPI 3的发布与系统集成

[原创] SpringFox 3.0.0(包含springfox-swagger2-3.0.0)的发布与系统集成一. SpringFox 3.0.0 发布A. 此版本的亮点B. 兼容性说明C. 此版本已修补的漏洞二. 系统如何集成?A. swagger2-3.0 maven依赖加入,非常方便,只需一个B. swagger2-3.0配置代码,通用型C. 系统启动效果展示D. 切换成bootstrap-ui 一. SpringFox 3.0.0 发布 SpringFox 3.0.0 发布了,SpringFox

在技术的广袤天地里,本博客如精准罗盘。剖析前沿科技,深掘代码奥秘,以精炼笔触,带您穿越复杂技术迷宫,速达知识彼岸。 1万+

SpringBoot 集成swagger3.0

SpringBoot 集成swagger3.0

qq_29534197的博客 1407

SpringBoot与Swagger集成及API文档导出实战教程

Swagger2是一个流行的API开发工具,它可以帮助开发者设计、构建、记录和使用RESTful Web服务。通过Swagger2,可以快速生成清晰的API文档,这些文档不仅便于开发人员参考,还让非技术性用户能够理解API的使用方法。在SpringBoot项目中集成Swagger2,可以极大地提高API开发的效率与便捷性。Swagger UI的界面布局大致可以分为三部分:API文档概览区:列出了所有分组的API文档,可以点击不同的分组进行查看。API详细信息区。

weixin_35045970的博客 890

Spring Boot与Swagger集成及logback日志管理教程

RESTful API已成为互联网服务的事实标准,它提供了一种简单、统一且易于访问的接口设计方式。Swagger是目前最流行的REST API文档生成工具之一,它允许开发者通过注释的方式,在编码过程中自动生成接口文档,提高了开发效率和文档的可维护性。Spring Boot作为当下流行的Java开发框架,其核心特性之一便是自动配置。自动配置简化了项目的搭建和开发流程,它基于类路径下依赖的jar包信息来推断应用需要的配置,并自动添加相应的Bean定义。

weixin_32312889的博客 974

Spring Boot 集成 Swagger 简易教程

Swagger Swagger号称是史上最流行的、最好用的API接口文档构建工具,它支持多种语言包括Java在内,本文仅关注如何使用Spring Boot来集成Swagger,更多关于Swagger的介绍可以查看以下几个链接。 Swagger - 官网Swagger - Github SpringFox   SpringFox最初叫Swagger-SpringMVC,...

happyJared 2679

从‘最长白列’到‘八邻域’:智能车图像巡线算法怎么选?我的踩坑经验分享

本文深入探讨了全国大学生智能汽车竞赛中图像巡线算法的选型与优化,对比了最长白列法、八邻域算法等五种主流方法的性能与适用场景。通过实战数据和代码示例,分析了各算法在直道、弯道及特殊赛道元素中的表现,并提供了内存优化、参数调整等实用技巧,帮助参赛团队提升智能车的巡线精度与效率。

weixin_30374009的博客 643

Spring Boot 集成 Swagger2 教程

Spring Boot 集成 Swagger2 教程1 创建一个 Spring Boot 项目2 Pom.xml 依赖管理3 编写示例代码3.1 配置 Swagger3.2 注解概述3.2 示例代码3.2.1 实体类代码 domain/UserDO.java3.3.2 控制层代码 UserController.java3.2.3 测试最终效果4 使用 swagger-bootstrap-ui 美化...

fishpro的博客 415

华为昇腾 910B 实战:DeepSeek-R1 蒸馏模型高效部署与性能调优全解析

本文详细解析了在华为昇腾910B硬件平台上高效部署DeepSeek-R1蒸馏系列模型(14B/32B版本)的完整实战流程。内容涵盖从MindIE环境搭建、镜像获取、模型准备,到服务配置、内存参数调优、性能测试及常见问题排查,为开发者提供了基于昇腾910B进行大模型部署与优化的全链路指南。

weixin_28235513的博客 214

DeepSeek-V3本地Docker容器化部署

通过以上步骤,你可以在本地上成功通过容器化部署DeepSeek-V3。安装完成后,启动Docker Desktop。如果需要后台运行,可以加上。

u013302168的博客 2125

springboot2.x集成swagger保姆级教程

Swagger 是一款用于 API(应用程序接口)设计、开发、文档化及测试的工具框架,可简化 API 全生命周期管理。它通过标准化规范(OpenAPI)定义接口,自动生成交互式文档、客户端 / 服务端代码,支持在线调试,提升前后端协作效率,常见于 RESTful API 开发,核心工具包括 Swagger UI(可视化文档)、Swagger Editor(接口设计)等,让 API 开发更透明、高效。

qq_44959735的博客 1345

【外挂编程】外挂编程技术揭秘(二)

引言: 经过上一篇文章大家可能对外挂有了一个初步的认识,之前的内容比较简单,应该大家很容易掌握。我写作过程中我发现三个篇幅可能写不完,后续还可能要多加几个篇幅,这篇我们就先以内存挂为主吧。话不多说了,让我们开始吧。 文章中代码github地址: https://github.com/Diamonds-ZhaoYu/hz_example 环境要求: 系统:Windows 语言...

c-rain 4038

SpringBoot集成Swagger教程

SpringBoot集成Swagger教程一 .Swagger介绍二.springboot集成swagger 一 .Swagger介绍 1.对于后端开发人员来说 不用再手写Wiki接口拼大量参数,避免手写错误 对代码侵入性低,采用全注解的方式,开发简单 方法参数名修改、新增、减少参数都可以直接生效,不用手动维护 缺点:增加了开发成本,写接口还得再写一套参数配置 2.对前端开发来说 后端只需要定义好接口,会自动生成文档,接口功能、参数一目了然 联调方便,如果出了问题,直接测试接口,实时检查参数

少年的博客 971

超详细 | 贝叶斯网络基础——有图有真相

Hello,大家好,我是starz。这是本系列的第二篇《概率基础Ⅱ》,虽说是概率基础,但作为过渡,它开始以图为载体 这节的主要内容有: 贝叶斯网络 三种结构 D-划分 贝叶斯球 马尔科夫毯 应用例子 总结 让我们开始吧 :3 贝叶斯网络 概率图模型可笼统分为两类,一是基于无向图的马尔科夫网络: 二是基于有向图的贝叶斯...

qq_41603411的博客 2万+

uniapp:使用uni.request请求报错errMsg“:“request:fail abort statusCode:-1(uniApp使用uni.request向服务端接口发起请求失败报错)

解决request请求报错request:fail abort statusCode:-1,Uniapp打包到app后报错request:fail abort statusCode:-1,uniapp使用uni.request请求报错{“errMsg“:“request:fail abort statusCode:-1“}的解决办法,不是SSL证书问题,跳过ssl验证,解决https问题,Uniapp报错,小程序报错(含https解决方案)(真机预览问题)uni-app打包后不发请求的原因,uni-app真

✅ 精选推荐文章 3582

swagger集成到springboot教程

springboot+swagger+mybatis工程,介绍swagger如何集成进springboot工程中,3分钟快速看懂!

程序员小杨哥的博客 3874

【量化入门】Tushare库获取公募基金的历史净值

在本文中,我们将介绍如何使用Python的Tushare库获取公募基金的历史净值。

木头大左的博客 1146

六、spring boot教程--集成swagger

spring boot教程--集成swagger一、swagger简介二swagger使用方法1.引入swagger的jar包2.编写swagger配置类3.控制器中代码三、运行效果 一、swagger简介 Swagger 是一个规范和完整的框架,用于生成、描述、调用和可视化 RESTful 风格的 Web 服务。总体目标是使客户端和文件系统作为服务器以同样的速度来更新。文件的方法,参数和模型紧密...

pin621的博客 319

AI测试:手把手教你用AI生成测试用例并支持导出Excel「喂饭教程」

如果我告诉你,有一种方法,你只需要输入需求内容,AI就能自动帮你设计出结构清晰、覆盖全面的测试用例,并直接生成一份精美的Excel表格,你会不会心动?

blues_C的博客 3885

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

Spring Boot教程(17)-Spring Boot集成Swagger

一、 S Sr wagger 是什么? Swagger 是一个规范和完整的框架,用于生成、描述、调用和可视化 RESTful 风格的 Web 服务。http://swagger.io/ Springfox 的前身是 swagger-springmvc,是一个开源的 API doc 框架,可以将我们的 Controller 的方法以文档的形式展现,基于 Swagger。...

Angus博客 632

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

Spring Boot 集成 Swagger2实战教程

Spring Boot 集成 Swagger添加依赖在 Spring Boot 配置文件中添加配置参数。添加配置类如何使用 添加依赖 Maven依赖示例: <!-- Swagger --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> </dependency> <dependency&g

Su*yWGAtH26Q 212

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

SpringBoot集成swagger2教程

1 第一步添加依赖 maven 引入pom直接集成spring boot <dependency> <groupId>com.spring4all</groupId> <artifactId>swagger-spring-boot-starter</artifactId> <version>1.9.1.RELEASE</version> </dependency> 2 配置 创.

张凯强的博客 390
下一篇: axios与跨域解决代码
Java|小白
博客等级 码龄5年 8粉丝 8原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值