引入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>