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.

解决方法同上。

相关推荐
索荣荣20 分钟前
Java Session 全面指南:原理、应用与实践(含 Spring Boot 实战)
java·spring boot·后端
向阳开的夏天20 分钟前
麒麟V10源码编译QT5.6.3 (x86 & arm64)
开发语言·qt
Amumu1213825 分钟前
Vue Router(二)
java·前端
Evand J41 分钟前
【MATLAB例程】TOA和TDOA混合定位,适用于二维平面的高精度定位。锚点数量、位置、测量噪声可自行调节
开发语言·matlab·定位·tdoa
念越1 小时前
数据结构:栈堆
java·开发语言·数据结构
淮北4941 小时前
pip虚拟环境包的问题
开发语言·python·pip
千寻技术帮1 小时前
10333_基于SpringBoot的家电进存销系统
java·spring boot·后端·源码·项目·家电进存销
dear_bi_MyOnly1 小时前
【多线程——线程状态与安全】
java·开发语言·数据结构·后端·中间件·java-ee·intellij-idea
常年游走在bug的边缘1 小时前
掌握JavaScript作用域:从函数作用域到块级作用域的演进与实践
开发语言·前端·javascript
jiaguangqingpanda2 小时前
Day36-20260204
java·开发语言