Java项目硅谷课堂后端报错处理

Java项目硅谷课堂后端报错处理总结

  • 前言
  • service_vod报错
  • gateway报错
    • [Failed to configure a DataSource](#Failed to configure a DataSource)
    • [UnsatisfiedDependencyException: Error creating bean with name 'gatewayConfigurationService'](#UnsatisfiedDependencyException: Error creating bean with name 'gatewayConfigurationService')
    • [Spring MVC found on classpath, which is incompatible with Spring Cloud Gateway at this time. Please remove spring-boot-starter-web dependency.](#Spring MVC found on classpath, which is incompatible with Spring Cloud Gateway at this time. Please remove spring-boot-starter-web dependency.)

前言

首先附上教学项目的B站地址:【尚硅谷&腾讯云】Java项目硅谷课堂丨微服务丨在线学习平台

本人只学习到93章。

service_vod报错

import javax.servlet.http.HttpServletResponse;找不到

在service_vod的pom文件中添加依赖:

java 复制代码
<dependency>
    <groupId>jakarta.servlet</groupId>
    <artifactId>jakarta.servlet-api</artifactId>
</dependency>

java.lang.IllegalStateException

发生这一错误的原因在于版本冲突,各位可以在idea打开的pom文件中,按键Ctrl + Alt + shift + u,打开依赖图查看,如有红线则为冲突。

根据项目依赖导入一般是不会有错的,而我遇到则是因为在service中去掉依赖:

java 复制代码
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

去掉原因为:网关开启后提示去掉该依赖。如各位也和我一样,那么一定注意,将该依赖从service中去掉的同时,加入除开gateway模块的service中其他所有模块。

否则产生:idea中服务启动,但实际上无法使用端口,服务并未真正启动。

gateway报错

Failed to configure a DataSource

参考链接

在项目网关模块启动类上加入注解
@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})

原因: SpringBoot 自动配置默认项目连接数据库,会扫描配置文件以连接数据库,而在我们的配置文件中没有相关配置。因为微服务中的网关服务不需要配置数据库,此时就会产生该错误。

UnsatisfiedDependencyException: Error creating bean with name 'gatewayConfigurationService'

去掉service中的依赖:

java 复制代码
<!--        &lt;!&ndash;web 需要启动项目&ndash;&gt;-->
<!--        <dependency>-->
<!--            <groupId>org.springframework.boot</groupId>-->
<!--            <artifactId>spring-boot-starter-web</artifactId>-->
<!--        </dependency>-->

Spring MVC found on classpath, which is incompatible with Spring Cloud Gateway at this time. Please remove spring-boot-starter-web dependency.

解决方法同上。

相关推荐
m0_5873830010 分钟前
碰碰好评卡功能落地实战 从需求梳理到上线部署全流程实操指南
java·linux·服务器·前端·javascript·vue.js·人工智能
普通人616 分钟前
php处理百度编辑器有误html
开发语言·编辑器·html·php·1024程序员节
沉下心来学鲁班24 分钟前
具身智能入门:用 Python 让 MicroDuck 机器狗学会走路
开发语言·人工智能·python·机器人
geovindu25 分钟前
rust: Chain of Responsibility Pattern (续)
开发语言·后端·设计模式·rust·责任链模式·行为模式
诚心呈意共享外卖配送系统26 分钟前
多平台订单聚合系统的技术架构:接 API 只是开始
java·开发语言·架构·系统架构·创业创新
Java爱好狂.31 分钟前
Java小白如何三天速通redis?
java·数据库·redis·架构师·分布式锁·java面试·java程序员
大风起兮云飞扬丶32 分钟前
Java——多线程
java
天若有情67342 分钟前
从零搭建校园二手交易系统:Vue2 + SpringBoot 4.x 全栈实战
java·spring boot·后端
学逆向的43 分钟前
C 浮点数e(科学计数法)
c语言·开发语言·网络安全
lexiangqicheng1 小时前
1,自定义表单通俗理解-PC设计APP渲染
java·前端·javascript