问题描述
- 使用 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:
解决方式,引入上述依赖即可