springcloud初始搭建并集成swagger2

我爱海鲸 2022-07-18 18:05:51 暂无标签

简介微服务

1、项目全局配置文件:pom.xml

   <parent>

        <artifactId>spring-boot-starter-parent</artifactId>

        <groupId>org.springframework.boot</groupId>

        <version>2.0.7.RELEASE</version>

    </parent>

 

    <dependencies>

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-web</artifactId>

        </dependency>

        <!-- JDK 9缺失jar -->

        <dependency>

            <groupId>com.sun.xml.bind</groupId>

            <artifactId>jaxb-impl</artifactId>

            <version>2.3.0</version>

        </dependency>

 

        <dependency>

            <groupId>com.sun.xml.bind</groupId>

            <artifactId>jaxb-core</artifactId>

            <version>2.3.0</version>

        </dependency>

 

        <dependency>

            <groupId>com.sun.xml.bind</groupId>

            <artifactId>jaxb-impl</artifactId>

            <version>2.3.0</version>

        </dependency>

 

        <dependency>

            <groupId>javax.activation</groupId>

            <artifactId>activation</artifactId>

            <version>1.1.1</version>

        </dependency>

 

        <dependency>

            <groupId>org.projectlombok</groupId>

            <artifactId>lombok</artifactId>

            <optional>true</optional>

        </dependency>

    </dependencies>

 

    <dependencyManagement>

        <dependencies>

            <dependency>

                <groupId>org.springframework.cloud</groupId>

                <artifactId>spring-cloud-dependencies</artifactId>

                <version>Finchley.SR2</version>

                <type>pom</type>

                <scope>import</scope>

            </dependency>

        </dependencies>

    </dependencyManagement>

项目结构:

undefined

2、搭建配置中心

配置中心pom.xml配置文件:

    <dependencies>

        <dependency>

            <groupId>org.springframework.cloud</groupId>

            <artifactId>spring-cloud-config-server</artifactId>

            <version>2.0.2.RELEASE</version>

        </dependency>

    </dependencies>

undefined

application.yml配置文件:

server:

  port: 8762

spring:

  application:

    name: configserver

  profiles:

    active: native

  cloud:

    config:

      server:

        native:

          search-locations: classpath:/shared

undefined

在配置中心配置的其他服务的配置user-dev.yml:

server:

  port: 8040

spring:

  application:

    name: user

  datasource:

    name: d_weblog

    username:12345

    password: 12345

    url: jdbc:mysql://123456

    driver-class-name: com.mysql.cj.jdbc.Driver

eureka:

  client:

    service-url:

      defaultZone: http://localhost:8761/eureka/

  instance:

    prefer-ip-address: true

mybatis:

  mapper-locations: classpath:/mapping/*.xml

  type-aliases-package: xyz.haijin.weblog.entity

服务启动:

undefined

3、搭建注册中心

pom.xml:

    <dependencies>

        <dependency>

            <groupId>org.springframework.cloud</groupId>

            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>

            <version>2.0.2.RELEASE</version>

        </dependency>

    </dependencies>

undefined

application.yml配置文件:

server:

  port: 8761

eureka:

  client:

    service-url:

      defaultZone: http://localhost:8761/eureka/

    register-with-eureka: false

    fetch-registry: false

  instance:

服务启动:

undefined

4、搭建业务微服务:

pom.xml配置文件

<dependencies>

        <dependency>

            <groupId>org.springframework.cloud</groupId>

            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>

            <version>2.0.2.RELEASE</version>

        </dependency>

 

        <dependency>

            <groupId>org.mybatis.spring.boot</groupId>

            <artifactId>mybatis-spring-boot-starter</artifactId>

            <version>1.3.1</version>

        </dependency>

 

        <dependency>

            <groupId>mysql</groupId>

            <artifactId>mysql-connector-java</artifactId>

            <version>8.0.19</version>

        </dependency>

 

        <dependency>

            <groupId>org.springframework.cloud</groupId>

            <artifactId>spring-cloud-starter-config</artifactId>

            <version>2.0.2.RELEASE</version>

        </dependency>

 

        <!-- swagger2 -->

        <dependency>

            <groupId>io.springfox</groupId>

            <artifactId>springfox-swagger2</artifactId>

            <version>2.9.2</version>

        </dependency>

        <dependency>

            <groupId>com.github.xiaoymin</groupId>

            <artifactId>swagger-bootstrap-ui</artifactId>

            <version>1.9.2</version>

        </dependency>

    </dependencies>

undefined

swagger配置:

undefined

接口文档:

undefined

服务启动:

undefined

5、其他的具体业务和springmvc并无二至,请自行编写

2022-07-18 start:

6、swagger集成springboot2.6出现的错误解决

springboot 2.6.x整合swagger2 3.0.0报错异常整理及解决办法

swagger2报错Illegal DefaultValue null for parameter type integer

end

你好:我的2025