SpringBoot_springfox-swagger版本升级处理

文章目录

  • 前言
  • 正文
    • springfox-swagger 2.7.0 集成方法
      • maven依赖
      • Java Config
    • springfox-swagger 2.10.5 集成方法
      • maven依赖
      • Java Config
  • 总结

前言

使用springfox-swagger2 + swagger-bootstrap-ui 升级实现2.7.0->2.10.5,发现高版本的配置方式与低版本配置存在差异,因此记录处理过程

正文

springfox-swagger 2.7.0 集成方法

maven依赖

    <properties>

        <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
        <maven.compiler.source>11maven.compiler.source>
        <maven.compiler.target>11maven.compiler.target>

        <maven-compiler-plugin.version>3.8.1maven-compiler-plugin.version>
        <flatten-maven-plugin.version>1.2.7flatten-maven-plugin.version>
        <maven-source-plugin.version>3.0.1maven-source-plugin.version>

        <spring-boot.version>2.3.2.RELEASEspring-boot.version>

        
        <springfox-swagger.version>2.7.0springfox-swagger.version>
        <swagger-bootstrap-ui.version>1.9.6swagger-bootstrap-ui.version>
    properties>

    <dependencyManagement>
        <dependencies>
            
            <dependency>
                <groupId>io.springfoxgroupId>
                <artifactId>springfox-swagger2artifactId>
                <version>${springfox-swagger.version}version>
            dependency>

            
            <dependency>
                <groupId>io.springfoxgroupId>
                <artifactId>springfox-swagger-uiartifactId>
                <version>${springfox-swagger.version}version>
            dependency>

            <dependency>
                <groupId>com.github.xiaoymingroupId>
                <artifactId>swagger-bootstrap-uiartifactId>
                <version>${swagger-bootstrap-ui.version}version>
            dependency>
        dependencies>
    dependencyManagement>

Java Config

@EnableSwagger2
@SpringBootApplication
public class SampleApplication {
    public static void main(String[] args) {
        SpringApplication.run(SampleApplication.class, args);
    }
}

springfox-swagger 2.10.5 集成方法

maven依赖

    <properties>

        <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
        <maven.compiler.source>11maven.compiler.source>
        <maven.compiler.target>11maven.compiler.target>

        <maven-compiler-plugin.version>3.8.1maven-compiler-plugin.version>
        <flatten-maven-plugin.version>1.2.7flatten-maven-plugin.version>
        <maven-source-plugin.version>3.0.1maven-source-plugin.version>

        <spring-boot.version>2.3.2.RELEASEspring-boot.version>

        
        <springfox-swagger.version>2.10.5springfox-swagger.version>
        <swagger-bootstrap-ui.version>1.9.6swagger-bootstrap-ui.version>
    properties>

    <dependencyManagement>
        <dependencies>
            
            <dependency>
                <groupId>io.springfoxgroupId>
                <artifactId>springfox-swagger2artifactId>
                <version>${springfox-swagger.version}version>
                <scope>compilescope>
            dependency>

            <dependency>
                <groupId>io.springfoxgroupId>
                <artifactId>springfox-spring-webmvcartifactId>
                <version>${springfox-swagger.version}version>
            dependency>

            
            <dependency>
                <groupId>io.springfoxgroupId>
                <artifactId>springfox-swagger-uiartifactId>
                <version>${springfox-swagger.version}version>
                <scope>compilescope>
            dependency>

            <dependency>
                <groupId>com.github.xiaoymingroupId>
                <artifactId>swagger-bootstrap-uiartifactId>
                <version>${swagger-bootstrap-ui.version}version>
            dependency>
        dependencies>
    dependencyManagement>

Java Config

@EnableSwagger2WebMvc
@SpringBootApplication
public class SampleApplication {
    public static void main(String[] args) {
        SpringApplication.run(SampleApplication.class, args);
    }
}

总结

使用springfox-swagger2 + swagger-bootstrap-ui 升级实现2.7.0->2.10.5 需要改造

  1. 升级依赖版本 并补充springfox-spring-webmvc模块
  2. 注解启动 @EnableSwagger2 修改为@EnableSwagger2WebMvc

你可能感兴趣的:(springboot,spring,boot,java,spring)