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.

解决方法同上。

相关推荐
渣哥1 分钟前
Java CyclicBarrier 详解:原理、使用方式与应用场景
java
杨杨杨大侠7 分钟前
打开 JVM 黑匣子——走进 Java 字节码(一)
java·jvm·agent
SimonKing9 分钟前
接口调用总失败?试试Spring官方重试框架Spring-Retry
java·后端·程序员
咖啡Beans10 分钟前
SpringCloud网关Gateway功能实现
java·spring cloud
杨杨杨大侠11 分钟前
Atlas Mapper 案例 01:初级开发者 - 电商订单系统开发
java·开源·github
华仔啊11 分钟前
Java 8都出了这么多年,Optional还是没人用?到底卡在哪了?
java
用户0914 分钟前
Gradle Cache Entries 深度探索
android·java·kotlin
叽哥35 分钟前
Kotlin学习第 9 课:Kotlin 实战应用:从案例到项目
android·java·kotlin
阿杆1 小时前
同事嫌参数校验太丑,我直接掏出了更优雅的 SpEL Validator
java·spring boot·后端
Grey Zeng10 小时前
Java SE 25新增特性
java·jdk·jdk新特性·jdk25