問題描述
- 使用 SpringCloud 搭建的項目,現啓動三個模塊,register(註冊中心)、gateway(網關)、user(用戶服務),啓動 user 時拋出異常:
ClassNotFoundException: org.springframework.http.ResponseEntity
查看導致的原因
- Spring Boot 項目在啓動時,有個依賴是必須導入的,而在我引入的依賴中,並沒有包含這個依賴:
<dependencies>
<!--springboot web模塊支持,自動幫我們引入了web模塊開發需要的相關jar包-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
爲什麼 register、gateway 兩個模塊裏面沒有引入,啓動卻沒有問題
- 原因在於,這兩個模塊引入的依賴中,已經包含了這個依賴,gateway 比較特殊,它包含的依賴是 webflux:
解決方式,引入上述依賴即可