美文网首页
spring boot 2.5.5 + dubbo 2.7.8

spring boot 2.5.5 + dubbo 2.7.8

作者: 待孤君临天下 | 来源:发表于2023-04-17 17:35 被阅读0次

版权声明:本文为博主原创文章,转载请注明出处【by:待孤君临天下

前言:记录下安装过程以便下次有需要无需百度!

PS:这里用的是 Jdk 17.0.4.1,并且用的是 undertow 容器

如果是 Jdk 1.8 升级到 jdk 17 的话 pom.xml 文件需要调整

<properties>
        <!--   jdk   -->
        <java.version>17</java.version>
        <!--   jaxb   -->
        <jaxb.version>2.4.0-b180830.0359</jaxb.version>
</properties>

<!--   jdk 9 or higher no javax jar   -->
<dependency>
  <groupId>javax.xml.bind</groupId>
  <artifactId>jaxb-api</artifactId>
  <version>${jaxb.version}</version>
</dependency>

1、修改 pom.xml 里面的 properties

spring boot 2.5.5 pom.xml 里面的 properties
PS:这里没有 dubbo 的问题在于 引用了 spring-cloud-starter-dubbo

<properties>
  <!--   spring-boot   -->
  <spring-boot.version>2.5.5</spring-boot.version>
  <!--   spring-cloud   -->
  <spring-cloud.version>2020.0.4</spring-cloud.version>
  <!--   spring-cloud-alibaba   -->
  <spring-cloud-alibaba.version>2021.1</spring-cloud-alibaba.version>
</properties>

spring boot 3.0.5 pom.xml 里面的 properties

<properties>
  <!--   spring-boot   -->
  <spring-boot.version>3.0.5</spring-boot.version>
  <!--   spring-cloud   -->
  <spring-cloud.version>2022.0.2</spring-cloud.version>
  <!--   spring-cloud-alibaba   -->
  <spring-cloud-alibaba.version>2022.0.0.0-RC1</spring-cloud-alibaba.version>
  <!--   dubbo   -->
  <dubbo.version>3.2.0</dubbo.version>
</properties>

2、包引用的替换

旧 dubbo 包的应用

<!-- dubbo -->
<dependency>
  <groupId>com.alibaba.cloud</groupId>
  <artifactId>spring-cloud-starter-dubbo</artifactId>
</dependency>

dubbo 3.0 的引用
PS:这里 dubbo 包之所有排除 fastjson2 是因为外面有单独的引用并且版本是不一样的

<!-- dubbo-spring-boot-starter -->
<dependency>
  <groupId>org.apache.dubbo</groupId>
  <artifactId>dubbo-spring-boot-starter</artifactId>
</dependency>

<!-- dubbo-registry-nacos -->
<dependency>
  <groupId>com.alibaba.nacos</groupId>
  <artifactId>nacos-client</artifactId>
</dependency>

<!-- duubo -->
<dependency>
  <groupId>org.apache.dubbo</groupId>
  <artifactId>dubbo</artifactId>
  <exclusions>
    <exclusion>
      <groupId>com.alibaba.fastjson2</groupId>
      <artifactId>fastjson2</artifactId>
    </exclusion>
  </exclusions>
</dependency>

3、dependencyManagement 新增

这里之所以多了个 snakeyaml是因为 redis 及其 nacos 里面引用的版本是 1.33,这个版本是有漏洞的,会提示 Provides transitive vulnerable dependency maven:org.yaml:snakeyaml:1.33

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-dependencies</artifactId>
      <version>${spring-cloud.version}</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-dependencies</artifactId>
      <version>${spring-boot.version}</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
    <dependency>
      <groupId>com.alibaba.cloud</groupId>
      <artifactId>spring-cloud-alibaba-dependencies</artifactId>
      <version>${spring-cloud-alibaba.version}</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.dubbo</groupId>
      <artifactId>dubbo-bom</artifactId>
      <version>${dubbo.version}</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
    <dependency>
      <groupId>org.yaml</groupId>
      <artifactId>snakeyaml</artifactId>
      <version>2.0</version>
    </dependency>
  </dependencies>
</dependencyManagement>

完整的 pom.xml 文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>***</groupId>
    <artifactId>***</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>***</name>
    <description>***</description>

    <properties>
        <!--   jdk   -->
        <java.version>17</java.version>
        <!--   sourceEncoding   -->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <!--   outputEncoding   -->
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <!--   jaxb   -->
        <jaxb.version>2.4.0-b180830.0359</jaxb.version>
        <!--   spring-boot   -->
        <spring-boot.version>3.0.5</spring-boot.version>
        <!--   spring-cloud   -->
        <spring-cloud.version>2022.0.2</spring-cloud.version>
        <!--   spring-cloud-alibaba   -->
        <spring-cloud-alibaba.version>2022.0.0.0-RC1</spring-cloud-alibaba.version>
        <!--   dubbo   -->
        <dubbo.version>3.2.0</dubbo.version>
        <!--   mysql   -->
        <mysql.version>8.0.32</mysql.version>
        <!--   mybatis-plus   -->
        <mybatis-plus.version>3.5.3.1</mybatis-plus.version>
        <!--  druid   -->
        <druid.version>1.2.17</druid.version>
        <!--   fastjson   -->
        <fastjson.version>2.0.27</fastjson.version>
    </properties>

    <dependencies>

        <!-- redis -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>

        <!--   spring boot aop   -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-aop</artifactId>
        </dependency>

        <!-- nacos-config -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
        </dependency>

        <!-- nacos-discovery -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>

        <!-- dubbo-spring-boot-starter -->
        <dependency>
            <groupId>org.apache.dubbo</groupId>
            <artifactId>dubbo-spring-boot-starter</artifactId>
        </dependency>

        <!-- dubbo-registry-nacos -->
        <dependency>
            <groupId>com.alibaba.nacos</groupId>
            <artifactId>nacos-client</artifactId>
        </dependency>

        <!-- duubo -->
        <dependency>
            <groupId>org.apache.dubbo</groupId>
            <artifactId>dubbo</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>com.alibaba.fastjson2</groupId>
                    <artifactId>fastjson2</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- security -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <!-- web -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!--   undertow   -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-undertow</artifactId>
        </dependency>

        <!-- bootstrap -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-bootstrap</artifactId>
        </dependency>

        <!-- mybatis-plus -->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>${mybatis-plus.version}</version>
        </dependency>

        <!-- mysql -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql.version}</version>
            <scope>runtime</scope>
        </dependency>

        <!--   druid   -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>${druid.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter</artifactId>
        </dependency>

        <!--   okhttp   -->
        <dependency>
            <groupId>com.squareup.okhttp3</groupId>
            <artifactId>okhttp</artifactId>
        </dependency>

        <!-- lombok -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>

        <!-- fastjson -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>${fastjson.version}</version>
        </dependency>

        <!-- test -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- security-test -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!--   jdk 9 or higher no javax jar   -->
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>${jaxb.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
        </dependency>

        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>31.1-jre</version>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                <version>${spring-cloud-alibaba.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.dubbo</groupId>
                <artifactId>dubbo-bom</artifactId>
                <version>${dubbo.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.yaml</groupId>
                <artifactId>snakeyaml</artifactId>
                <version>2.0</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.3.7.RELEASE</version>
                <configuration>
                    <mainClass>com.yy.bill.BillApplication</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <id>repackage</id>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

5、nacos 上 redis 和 undertow 配置变更

旧的 redis 和 undertow 配置

spring:
  redis:
    # Redis 数据库索引(默认0)
    database: 0
    # Redis 服务器地址
    host: localhost
    # Redis 服务器连接端口
    port: 6379
    # Redis 服务器连接密码
    password: ****

新的 redis 和 undertow 配置

server:
  undertow:
    threads:
      # 设置 undertow IO 线程数(一般是 CPU 个数)
      io: 4
      # IO 线程数 * 8
      worker: 32
    # 设置 undertow 每块 buffer 的空间大小
    buffer-size: 1024
    # 设置 undertow 是否分配的直接内存( NIO 直接分配的堆外内存)
    direct-buffers: true
spring:
  data:
    redis:
      # Redis 数据库索引(默认0)
      database: 0
      # Redis 服务器地址
      host: localhost
      # Redis 服务器连接端口
      port: 6379
      # Redis 服务器连接密码
      password: *****

6、nacos 上 dubbo 配置变化

dubbo 不需要在显示的配置订阅哪些服务了
如果不用 qos 不用的话,enable 设置为 false。
如果使用 qos 同一台多个服务需要配置端口
use-as-config-center、use-as-metadata-center 不生成配置文件

dubbo:
  application:
    metadata-type: local
    qos-enable: false
  scan:
    base-packages: com.**
  registry:
    address: nacos://localhost:8848
    use-as-config-center: false
    use-as-metadata-center: false
  protocol:
    name: dubbo
    port: -1
  consumer:
    timeout: 30000
    retries: 1
    check: false

7、启动类需要加上 @EnableDubbo

相关文章

网友评论

      本文标题:spring boot 2.5.5 + dubbo 2.7.8

      本文链接:https://www.haomeiwen.com/subject/kaecjdtx.html