Swagger和openCV与Springboot整合注意事项

排查了一天的BUG终于结束了

长话短说先把结论放在前头

一、结论:

1、目前Swagger与Springboot整合支持的最高版本:Springboot 2.7.6 和 Swagger 3.0.0

2、当你的Springboot项目需要使用Opencv的时候务必把Devtools依赖删掉

二、Swagger与Springboot整合

1、依赖导入

//Swagger Api
// https://mvnrepository.com/artifact/io.springfox/springfox-boot-starter
implementation 'io.springfox:springfox-boot-starter:3.0.0'

Gardle

<!-- https://mvnrepository.com/artifact/io.springfox/springfox-boot-starter -->
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-boot-starter</artifactId>
    <version>3.0.0</version>
</dependency>

Maven

不需要再导入 springfox-swagger-ui 和 springfox-swagger2 依赖

2、Swagger配置

/**
 * @作者 Lamzy
 * @日期 2022/12/5 1:45
 * @网站 http://gdei.lamzy.top
 * @描述 Swagger 配置
 * @版本 1.0.0
 */
package com.github.lamzier.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
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 java.util.ArrayList;

/**
 * @类名 SwaggerConfig
 * @描述 Swagger 配置
 * @作者 Lamzy
 * @日期 2022/12/5 1:45
 * @网站 http://gdei.lamzy.top
 * @版本 1.0.0
 */
@Configuration
public class SwaggerConfig {

    /**
     * 公开接口
     */
    @Bean
    public Docket groupPublic(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())//基本信息
                .groupName("公开接口")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.github.lamzier.controller.base"))//扫描包
                .build();
    }

    /**
     * 全部接口
     */
    @Bean
    public Docket groupAll(Environment environment){
        //设置要显示Swagger的环境
//        Profiles profiles = Profiles.of("dev");//测试环境显示
//        boolean flag = environment.acceptsProfiles(profiles);//获取是否属于此环境
        boolean flag = true;
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())//基本信息
                .enable(flag)//是否开启
                .groupName("全部接口");
    }

    //配置Swagger信息
    private ApiInfo apiInfo(){
        //作者信息
        Contact contact = new Contact("Lamzy" , "http://gdei.lamzy.top" , "1255461704@qq.com");
        return new ApiInfo("Lamzy的Api文档",
                "知行合一,止于至善。进德修业,为人师表。",
                "v1.0",
                "http://gdei.lamzy.top",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList<>());
    }

}

SwaggerConfig.java

可以省略 @EnableSwagger2 注解

三、OpenCV与Springboot整合

1、加载动态库

try {
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);//加载动态库 opencv_java455
}catch (Exception e){
    LOGGER.error("加载库加载失败!" + e);
}

四、参考资料

(3条消息) SpringBoot集成OpenCV进行图像处理_二两桃花酿作酒的博客-CSDN博客_springboot整合opencv

博客地址:Blog Single | LamBlog

五、闲聊茶厅

//devtools热部署 !! 千万不要添加热部署会导致opencv依赖库反复加载导致无法正常运行
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-devtools
//implementation 'org.springframework.boot:spring-boot-devtools:2.7.6'

短短的一句话,是我无数个小时的摸索

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值