引入dubbo后spring相关包全是引入的4.3.16版本的,例如:
spring-web-4.3.16.RELEASE.jar
spring-context-4.3.16.RELEASE.jar
等
而spring boot 2.x版本的spring版本都是5.x的
仔细检查了下pom文件,发现我dependencyManagement中少定义了spring boot版本下面为官方案例
<!-- Spring Boot --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>${spring-boot.version}</version> <type>pom</type> <scope>import</scope> </dependency> <!-- Apache Dubbo --> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-dependencies-bom</artifactId> <version>${dubbo.version}</version> <type>pom</type> <scope>import</scope> </dependency>
所以报错的原因就是我少了这个。于是我将如下依赖加入到dependencyManagement中就可以了:
<!-- Spring Boot --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>2.1.11.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency>