先看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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.zx</groupId>
<artifactId>dubbodemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>dubbodemo</name>
<description>dubbodemo</description>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-bom</artifactId>
<version>3.3.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
</dependency>
</dependencies>
</project>
看起来没有什么问题,但是启动时会报错
Exception in thread "main" java.lang.NoSuchMethodError: 'org.springframework.core.io.support.SpringFactoriesLoader org.springframework.core.io.support.SpringFactoriesLoader.forDefaultResourceLocation(java.lang.ClassLoader)'
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:466)
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:462)
at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:277)
at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:257)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1361)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1350)
at com.zx.dubbodemo.DubbodemoApplication.main(DubbodemoApplication.java:23)
第一感觉是有冲突,代码的版本不兼容
换一种写法,
1,换dubbo的引入方式,放弃bom引入,单个引入
<!-- <dependencyManagement>-->
<!-- <dependencies>-->
<!-- <dependency>-->
<!-- <groupId>org.apache.dubbo</groupId>-->
<!-- <artifactId>dubbo-bom</artifactId>-->
<!-- <version>3.3.0</version>-->
<!-- <type>pom</type>-->
<!-- <scope>import</scope>-->
<!-- </dependency>-->
<!-- </dependencies>-->
<!-- </dependencyManagement>-->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>3.3.0</version>
</dependency>
</dependencies>
启动ok
2025-01-11T14:26:10.578+08:00 INFO 12016 --- [dubbodemo] [ main] o.a.d.c.d.DefaultApplicationDeployer : [DUBBO] Dubbo Application[1.1](dubbo-demo) is ready., dubbo version: 3.3.0, current host: 192.168.2.33
2025-01-11T14:26:10.578+08:00 INFO 12016 --- [dubbodemo] [ main] o.a.d.c.deploy.DefaultModuleDeployer : [DUBBO] Dubbo Module[1.1.1] has completed., dubbo version: 3.3.0, current host: 192.168.2.33
2025-01-11T14:26:10.578+08:00 INFO 12016 --- [dubbodemo] [ main] o.a.d.c.d.DefaultApplicationDeployer : [DUBBO] Dubbo Application[1.1](dubbo-demo) has completed., dubbo version: 3.3.0, current host: 192.168.2.33
2025-01-11T14:26:10.580+08:00 INFO 12016 --- [dubbodemo] [ main] com.zx.dubbodemo.DubbodemoApplication : Started DubbodemoApplication in 1.632 seconds (process running for 2.138)
2025-01-11T14:26:10.584+08:00 INFO 12016 --- [dubbodemo] [pool-2-thread-1] .b.c.e.AwaitingNonWebApplicationListener : [Dubbo] Current Spring Boot Application is await...
2,去掉spring-boot-starter-parent 引入spring-boot-dependencies
<?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>
<!-- <parent>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-parent</artifactId>-->
<!-- <version>3.4.1</version>-->
<!-- <relativePath/> <!– lookup parent from repository –>-->
<!-- </parent>-->
<groupId>com.zx</groupId>
<artifactId>dubbodemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>dubbodemo</name>
<description>dubbodemo</description>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>3.4.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-bom</artifactId>
<version>3.3.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
</dependency>
</dependencies>
</project>
启动ok
虽然版本都一样,但是不同的写法却有着不同的结果
具体原因没有去调查,但决定用第二种写法