Weblogic启动报错“Expected single row from liquibase.statement.core.SelectFromDatabaseChangeLogLockState”

一、背景:

本地测试环境数据库模拟生产恢复之后启动报错

二、报错日志:

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping]: Factory method 'endpointHandlerMapping' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcEndpoints' defined in class path resource [org/springframework/boot/actuate/autoconfigure/EndpointWebMvcManagementContextConfiguration.class]: Invocation of init method failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'liquibaseEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/EndpointAutoConfiguration$LiquibaseEndpointConfiguration.class]: Unsatisfied dependency expressed through method 'liquibaseEndpoint' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [com/ideatech/common/config/LiquibaseConfig.class]: Invocation of init method failed; nested exception is liquibase.exception.LockException: liquibase.exception.DatabaseException: Expected single row from liquibase.statement.core.SelectFromDatabaseChangeLogLockStatement@1ae82a09 but got 2
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
        ... 116 common frames omitted

三、排查原因:(略过原因直接看解决方法的直接下一步)

      这个异常信息表明在 Spring Boot 应用程序启动时出现了问题,具体涉及到 Spring Boot Actuator 的端点配置以及 Liquibase 的初始化过程。

让我们逐步分析这个异常的主要问题和可能的解决方法:

异常根本原因是 liquibase.exception.LockException,提示 Liquibase 在执行数据库变更时出现了锁定问题。


异常链分析:

BeanInstantiationException:Spring 在实例化 EndpointHandlerMapping 过程中失败。
BeanCreationException:Spring 创建 mvcEndpoints bean 时发生了错误。
UnsatisfiedDependencyException:在创建 liquibaseEndpoint bean 时,依赖的 liquibase bean 初始化失败。
LockException:由 Liquibase 抛出的异常,指示数据库锁定问题。
DatabaseException:Liquibase 在执行数据库操作时遇到了问题。


具体错误:

Expected single row but got 2:Liquibase 在查询 DATABASECHANGELOGLOCK 表时预期返回一行,但实际返回了两行。这通常意味着多个 Liquibase 实例或者不同的线程尝试同时访问数据库变更日志表。
可能的解决方法:

确保唯一的 Liquibase 实例:确保你的应用程序只有一个 Liquibase 实例在执行数据库迁移。可能存在多个应用实例同时运行或者同一实例的多个 Liquibase 实例在操作数据库。

检查数据库状态:检查数据库中 DATABASECHANGELOGLOCK 表的状态,确保没有未释放的锁定。你可以手动检查数据库表,并清理掉多余的锁定行。

排查并发问题:检查应用程序的部署环境,确保不会出现并发启动多个 Liquibase 实例的情况。

使用数据库管理工具:可以使用数据库管理工具(如 SQL Developer、pgAdmin、MySQL Workbench 等)直接操作数据库表,查看和清理 DATABASECHANGELOGLOCK 表。

Spring Boot Actuator 配置调整:在某些情况下,可能需要调整 Spring Boot Actuator 的配置,以确保端点的正确初始化。但通常情况下,问题主要集中在 Liquibase 的数据库锁定问题上。

重新启动应用程序:

在清理了数据库锁定问题后,重新启动应用程序,看看问题是否解决。
通过理解并解决 DATABASECHANGELOGLOCK 表中的行数异常,应该能够解决这个 BeanInstantiationException 的根本问题

四、解决

1、原因

经排查确认数据库中系统表DATABASECHANCELOGLOOK为两条数据,删掉一条即可

删掉重启即可解决,但此时删除报错了😅

请看jpg(原因:ORA-01502 错误表示一个索引处于不可用状态)

2、检查索引状态:

SELECT index_name,status,owner FROM all_indexes WHERE index_name = 'PK_DATABASECHANCELOGLOOK';

如果STATUS列显示为UNUSABLE,则表示索引不可用。

3、重新构建索引:

ALTER INDEX 'PK_DATABASECHANCELOGLOOK REBUILD;

这将重新构建索引,使其恢复正常状态。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值