当前位置: 首页 > news >正文

spring-boot-autoconfigure误引入spring-boot-starter-data-jpa而导致数据源初始化异常

一、现状描述

某个Grade类引入了jpa的注解:

import javax.persistence.Column;
import javax.persistence.Embeddable;/*** 年级*/
@Embeddable
public class Grade {@Column(name = "code")private int code;
}

并且pom.xml中引入该jar包:spring-boot-starter-data-jpa

        <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jpa</artifactId></dependency>

不出意外,在启动的时候会报错如下:

2024-01-02 14:35:23.242  WARN [xxx-service,,,] 2778322 --- [           main] o.s.boot.actuate.endpoint.EndpointId     : Endpoint ID 'hystrix.stream' contains invalid characters, please migrate to a valid format.
2024-01-02 14:35:24.919  WARN [xxx-service,,,] 2778322 --- [           main] c.n.c.sources.URLConfigurationSource     : No URLs will be polled as dynamic configuration sources.2024-01-02 14:35:25.564 ERROR [xxx-service,,,] 2778322 --- [           main] o.s.b.web.embedded.tomcat.TomcatStarter  : Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: 
Error creating bean with name 'servletEndpointRegistrar' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]: 
Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: 
Factory method 'servletEndpointRegistrar' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'healthEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: 
Unsatisfied dependency expressed through method 'healthEndpoint' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthContributorRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: 
Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: 
Failed to instantiate [org.springframework.boot.actuate.health.HealthContributorRegistry]: Factory method 'healthContributorRegistry' threw exception; 
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthContributorAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; 
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: 
Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: 
Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class2024-01-02 14:35:25.595  WARN [xxx-service,,,] 2778322 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
Disconnected from the target VM, address: '127.0.0.1:35843', transport: 'socket'2024-01-02 14:35:25.625 ERROR [xxx-service,,,] 2778322 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : ***************************
APPLICATION FAILED TO START
***************************Description:Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.Reason: Failed to determine a suitable driver classAction:Consider the following:If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.If you have database settings to be loaded from a particular profile you may need to activate it (the profiles dev are currently active).

错误在于你没有配置rdb的数据源,默认是com.zaxxer.hikari.HikariDataSource。

可是我整个项目都只依赖Mongodb和redis数据库,并无需使用mysql等关系型数据库。

二、解决办法

1、方法一,忽略数据源的自动加载

在application.java启动类上作处理:

@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class})
public class XxxApplication {public static void main(String[] args) {SpringApplication.run(DataCenterAppApplication.class, args);}
}

2、方法二,去除数据源jdbc的依赖

		<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jpa</artifactId><exclusions><exclusion><artifactId>spring-boot-starter-jdbc</artifactId><groupId>org.springframework.boot</groupId></exclusion></exclusions></dependency>

3、方法三,去掉jpa(建议方法)

既然没有使用到关系型数据库,就没必要jpa包了。

这里需要说明的是,文章开头说的Grade类,是不必要那些字段的注解。

估计是从其他项目中将代码copy过来的时候,偷懒做法,没有去掉注解。

三、总结

1、查找mvn依赖关系,定位到Hikari包是被谁引入的。

通过问题的报错,反过去推导。

在这里插入图片描述

2、不要引入不必要的jar包,方法一和二虽然解决了问题,但多少有点画蛇添足的嫌疑。

当然,还有人会说,没配置rdb的数据源就配置啊。

这就非常提倡,为了一双玉的筷子,反过来去买一个金碗,再进而去买银碗篮。。。

相关文章:

spring-boot-autoconfigure误引入spring-boot-starter-data-jpa而导致数据源初始化异常

一、现状描述 某个Grade类引入了jpa的注解&#xff1a; import javax.persistence.Column; import javax.persistence.Embeddable;/*** 年级*/ Embeddable public class Grade {Column(name "code")private int code; }并且pom.xml中引入该jar包&#xff1a;sprin…...

工程(十六)——自己数据集跑Fast_livo

一、基础环境 Ubuntu20.04 ROS noetic PCL 1.8 Eigen 3.3.4 Sophus git clone https://github.com/strasdat/Sophus.git cd Sophus git checkout a621ff mkdir build && cd build && cmake .. make sudo make install 下面两个直接把包下载下来一起编译…...

PostgreSQL数据库的json操作

1.操作符 select json字段::json->key值 from order -- 对象域 select json字段::json->>key值 from order -- 文本 select json字段::json#>{key值} from order -- 对象域 select json字段::json#>>{key值} from order -- 文本对象域表示还能继续操作&#…...

gradio-osprey-demo

创建需要的dockerfle ################### # 使用 Ubuntu 作为基础镜像 FROM nvcr.io/nvidia/cuda:11.8.0-devel-ubuntu22.04 # 更新软件包列表并安装依赖项 RUN apt update && \ apt install -y python3 python3-pip git ffmpeg libsm6 libxext6 curl wget …...

从仿写持久层框架到MyBatis核心源码阅读

接上篇手写持久层框架&#xff1a;https://blog.csdn.net/liwenyang1992/article/details/134884703 MyBatis源码 MyBatis架构原理&主要组件 MyBatis架构设计 MyBatis架构四层作用是什么呢&#xff1f; API接口层&#xff1a;提供API&#xff0c;增加、删除、修改、查询…...

浏览器常用基本操作之python3+selenium4自动化测试

1、打开指定的网页地址 我们使用selenium进行自动化测试时&#xff0c;打开浏览器之后&#xff0c;第一步就是让浏览器访问我们指定的地址&#xff0c;可使用get方法实现 1 2 3 from selenium import webdriver driver webdriver.Edge() driver.get(https://www.baidu.com/)…...

在MySQL中使用VARCHAR字段进行日期筛选

&#x1f337;&#x1f341; 博主猫头虎&#xff08;&#x1f405;&#x1f43e;&#xff09;带您 Go to New World✨&#x1f341; &#x1f984; 博客首页——&#x1f405;&#x1f43e;猫头虎的博客&#x1f390; &#x1f433; 《面试题大全专栏》 &#x1f995; 文章图文…...

微信小程序自定义步骤条效果

微信小程序自定义一个步骤条组件&#xff0c;自定义文字在下面&#xff0c;已完成和未完成和当前进度都不一样的样式&#xff0c;可点击上一步和下一步切换流程状态&#xff0c;效果如下。 这是视频效果&#xff1a; 前端实现步骤条效果 下面我们一步步实现编码&#xff0c;自定…...

QT的信号与槽

QT的信号与槽 文章目录 QT的信号与槽前言一、QT 打印"hello QT"的dome二、信号和槽机制&#xff1f;二、信号与槽的用法1、QT5的方式1. 无参的信号与槽的dome2.带参的信号与槽dome 2、QT4的方式3、C11的语法 Lambda表达式1、函数对象参数2、操作符重载函数参数3、可修…...

Python 为UnityAndroid端自动化接入Tradplus广告SDK

Python 为UnityAndroid端自动化接入Tradplus广告SDK Tradplus介绍常规接入进入Android开发文档选择渠道配置生成接入代码人工依赖下载官网同版本的 Unity插件 使用自动化工具接入首次 你需要打两个标记来定位运行工具 控制台会列出最新的十个Tradplus版本 任选其一然后拖入项目…...

Matplotlib基础

目录&#xff1a; 一、绘制yx^2图像&#xff1a; 一、绘制yx^2图像&#xff1a; from matplotlib import pyplot as plt import numpy as np #生成&#xff08;-50,50&#xff09;的数组 x np.arange(-50,50) #计算因变量y的值 y x ** 2 #根据x、y数组绘制图形yx^2 plt.plot…...

上海东海职业技术学院低代码实训平台建设项目竞争性磋商公告

上海东海职业技术学院低代码实训平台建设项目竞争性磋商公告 招标&#xff5c;招标公告 上海市|闵行区 项目编号&#xff1a;0773-2340GNSHFWCS2823 招标单位&#xff1a;上海东海职业技术学院 代理单位&#xff1a;中金招标有限责任公司 预算金额&#xff1a;59万元 联系方式&…...

c语言之将输入的十进制转换成二进制数并打印原码反码补码

十进制转二进制 首先&#xff0c;我们要知道的是十进制转换成二进制数的方法。我们一般采用的除二取余的方法&#xff0c;在这里我用32位数组来进行转换。 int main() {printf("请输入一个十进制数\n");int n 0;scanf("%d", &n);int arr[32];int* p…...

算法题明明的随机数

第一行先输入随机整数的个数 N 。 接下来的 N 行每行输入一个整数&#xff0c;代表明明生成的随机数。 具体格式可以参考下面的"示例"。 import java.util.Iterator; import java.util.Scanner; import java.util.TreeSet; // 注意类名必须为 Main, 不要有任何 pa…...

B站不赚钱、“芒果”赚钱难,视频“后浪”火拼跨年夜

又是一年跨年时。 各大视频平台跨年晚会展开火拼&#xff0c;今年谁是赢家&#xff1f; 作为视频“后浪”&#xff0c;芒果超媒&#xff08;300413.SZ&#xff09;、哔哩哔哩&#xff08;09626.HK&#xff0c;下称“B站”&#xff09;此前相继公布了2023年三季报&#xff0c;…...

ajax请求的详细流程+详细示例

AJAX&#xff08;Asynchronous JavaScript and XML&#xff09;是一种用于创建异步 Web 应用程序的技术。下面是 AJAX 请求的详细流程&#xff1a; 创建 XMLHttpRequest 对象&#xff1a;在 JavaScript 代码中&#xff0c;使用 new XMLHttpRequest() 创建一个 XMLHttpRequest 对…...

这些产品手册制作工具,你都值得收藏

产品手册是企业向消费者传达产品信息的重要媒介&#xff0c;它能够直接影响消费者对产品的了解和购买决策。然而&#xff0c;制作一份专业而吸引人的产品手册并非易事&#xff0c;需要一定的设计和排版能力。为了帮助企业和个人更轻松地制作出优质的产品手册&#xff0c;下面将…...

跨账号和同账号的ECS云服务器之间迁移教程

阿里云ECS实例间迁移场景如下&#xff1a; 场景一&#xff1a;跨账号ECS实例间迁移 此场景适用于跨账号&#xff0c;同地域或者跨地域下的ECS实例间的迁移。例如&#xff1a;将阿里云账号A下的ECS实例&#xff0c;迁移阿里云B账号下。 场景二&#xff1a;同账号ECS实例间迁移 …...

python virtualenv 虚拟环境命令

# 安装 virtualenv pip3.9 install virtualenv # 创建虚拟环境test mkdir /envs # 创建一个文件夹放置虚拟环境 cd /envs/ virtualenv /envs/test # --pythonpython3.9 # 激活虚拟环境test source /envs/test/bin/activate # 安装依…...

深入理解MySQL索引底层数据结构

听课问题(听完课自己查资料) 什么是二叉树 二叉树是怎么存储数据的一个链表是一个集合的数据结构 List是怎么便利找到指定下标元素为什么会快&#xff1f;什么是红黑树 红黑树是怎么存储数据的什么是B TREE 是怎么存储数据的什么是BTREE 是怎么存储数据的 疑惑答案 a. 二叉树…...

攻克内核加载难题:OpenArk工具驱动加载失败的系统化解决策略

攻克内核加载难题&#xff1a;OpenArk工具驱动加载失败的系统化解决策略 【免费下载链接】OpenArk The Next Generation of Anti-Rookit(ARK) tool for Windows. 项目地址: https://gitcode.com/GitHub_Trending/op/OpenArk OpenArk作为新一代Windows反Rootkit工具&…...

NaViL-9B多模态提示词工程:提升图文理解准确率的10个实用技巧

NaViL-9B多模态提示词工程&#xff1a;提升图文理解准确率的10个实用技巧 1. 认识NaViL-9B多模态模型 NaViL-9B是一款原生支持多模态交互的大语言模型&#xff0c;能够同时处理文本和图像输入。与传统的纯文本模型不同&#xff0c;它可以直接"看懂"图片内容&#x…...

MusePublic圣光艺苑惊艳案例:基于真实建筑数据生成文艺复兴城市图景

MusePublic圣光艺苑惊艳案例&#xff1a;基于真实建筑数据生成文艺复兴城市图景 1. 引言&#xff1a;当古典建筑遇见AI画笔 想象一下&#xff0c;你手头有一份欧洲某座历史名城的建筑测绘数据&#xff0c;里面记录了数百座教堂、广场和宫殿的精确尺寸与风格特征。过去&#x…...

OpCore-Simplify:让黑苹果配置从复杂到简单的智能化革命

OpCore-Simplify&#xff1a;让黑苹果配置从复杂到简单的智能化革命 【免费下载链接】OpCore-Simplify A tool designed to simplify the creation of OpenCore EFI 项目地址: https://gitcode.com/GitHub_Trending/op/OpCore-Simplify 你是否曾为黑苹果&#xff08;Hac…...

终极指南:如何在Open Interpreter中快速集成vLLM高速推理引擎

终极指南&#xff1a;如何在Open Interpreter中快速集成vLLM高速推理引擎 【免费下载链接】open-interpreter Open Interpreter 工具能够让大型语言模型在本地执行如Python、JavaScript、Shell等多种编程语言的代码。 项目地址: https://gitcode.com/GitHub_Trending/op/open…...

RTX 4090D专属镜像应用场景:短视频MCN机构批量生成口播视频生产系统

RTX 4090D专属镜像应用场景&#xff1a;短视频MCN机构批量生成口播视频生产系统 1. 短视频行业的痛点与解决方案 短视频MCN机构每天面临的最大挑战之一&#xff0c;就是如何高效生产大量高质量的口播视频内容。传统制作流程通常需要&#xff1a; 租用专业摄影棚聘请主播录制…...

计算机网络 之 【自定义协议、序列化与反序列化】(C++使用JSON示例)

目录 1.自定义协议与序列化/反序列化 2.Json简介 Json是什么 第三方库提供&#xff0c;使用时包含头文件 JSON 的数据类型 JSON结构示例 C使用JSON示例 1.自定义协议与序列化/反序列化 协议的必要性 协议是通信双方的约定&#xff0c;它定义了数据的格式和含义&#xff…...

【Mojo跨语言互操作权威配置白皮书】:实测TensorFlow/NumPy/Pandas三方库零报错接入方案

第一章&#xff1a;Mojo跨语言互操作的核心原理与架构定位Mojo并非传统意义上的独立运行时语言&#xff0c;而是以“Python超集”为设计原点、深度嵌入LLVM生态的系统级编程语言。其跨语言互操作能力不依赖FFI桥接层或胶水代码&#xff0c;而是通过统一的中间表示&#xff08;M…...

MacBook Pro本地部署OpenClaw:百川2-13B量化模型7×24小时运行方案

MacBook Pro本地部署OpenClaw&#xff1a;百川2-13B量化模型724小时运行方案 1. 为什么选择MacBook Pro部署OpenClaw&#xff1f; 去年冬天&#xff0c;当我第一次尝试在MacBook Pro上部署量化版百川2-13B模型时&#xff0c;身边的朋友都觉得我疯了。"M1芯片能跑得动13B…...

FPGA状态机实战:用Verilog实现自动售卖机(附三段式完整代码)

FPGA状态机实战&#xff1a;用Verilog实现自动售卖机&#xff08;附三段式完整代码&#xff09; 在数字电路设计中&#xff0c;状态机是最核心的设计思想之一。它能够将复杂的控制逻辑分解为有限的状态和状态之间的转换&#xff0c;使得设计更加清晰、可维护。自动售卖机作为一…...