创建类路径资源中定义的名为“liquibase”的 bean 时出错.../config/DatabaseConfiguration.class

2024-05-11

在我的 jHipster 项目上启动嵌入式 Tomcat 时,我遇到了这个恼人的错误。花了很多时间试图解决它,但无法弄清楚为什么会发生。它是在主要代表更新项目后开始发生的,但我也实现了自定义存储库。

堆栈跟踪:

    DEBUG] uk.co.
config.DatabaseConfiguration - Configuring Liquibase
[WARN] org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext - Exception encountered d
uring context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path
 resource [uk/co/inspiresoft/config/DatabaseConfiguration.class]: Invocation of init method failed; nested exception is
liquibase.exception.ValidationFailedException: Validation Failed:
     1 change sets check sum
          classpath:config/liquibase/changelog/00000000000000_initial_schema.xml::00000000000001::jhipster is now: 7:bde
7b076d47aefe8278d126cde26b172

        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireC
apableBeanFactory.java:1574) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCap
ableBeanFactory.java:539) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapab
leBeanFactory.java:476) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spr
ing-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegis
try.java:230) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[sprin
g-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-
beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListable
BeanFactory.java:755) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplic
ationContext.java:757) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) ~
[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext
.java:118) [spring-boot-1.2.3.RELEASE.jar:1.2.3.RELEASE]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686) [spring-boot-1.2.3.RELEASE.jar
:1.2.3.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:320) [spring-boot-1.2.3.RELEASE.jar:1.2
.3.RELEASE]
        at uk.co.Application.main(Application.java:59) [classes/:na]
Caused by: liquibase.exception.ValidationFailedException: Validation Failed:
     1 change sets check sum
          classpath:config/liquibase/changelog/00000000000000_initial_schema.xml::00000000000001::jhipster is now: 7:bde
7b076d47aefe8278d126cde26b172

        at liquibase.changelog.DatabaseChangeLog.validate(DatabaseChangeLog.java:196) ~[liquibase-core-3.3.2.jar:na]
        at liquibase.Liquibase.update(Liquibase.java:196) ~[liquibase-core-3.3.2.jar:na]
        at liquibase.integration.spring.SpringLiquibase.performUpdate(SpringLiquibase.java:353) ~[liquibase-core-3.3.2.j
ar:na]
        at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:317) ~[liquibase-core-3.
3.2.jar:na]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowi
reCapableBeanFactory.java:1633) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireC
apableBeanFactory.java:1570) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
        ... 13 common frames omitted
[INFO] uk.co.config.CacheConfiguration - Closing Cache Manager
[INFO] com.hazelcast.core.LifecycleService - [192.168.1.48]:5701 [dev] [3.4] Address[192.168.1.48]:5701 is SHUTTING_DOWN

这是我的数据库配置类

    import java.util.Arrays;

import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;

import liquibase.integration.spring.SpringLiquibase;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.boot.bind.RelaxedPropertyResolver;
import org.springframework.context.ApplicationContextException;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import com.codahale.metrics.MetricRegistry;
import com.fasterxml.jackson.datatype.hibernate4.Hibernate4Module;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

@Configuration
@EnableJpaRepositories(repositoryFactoryBeanClass=uk.co.repository.IRepositoryFactoryBean.class, basePackages={"uk.co.repository"})
@EnableJpaAuditing(auditorAwareRef = "springSecurityAuditorAware")
@EnableTransactionManagement
public class DatabaseConfiguration implements EnvironmentAware {

    private final Logger log = LoggerFactory.getLogger(DatabaseConfiguration.class);

    private RelaxedPropertyResolver propertyResolver;

    private Environment env;

    @Autowired(required = false)
    private MetricRegistry metricRegistry;

    @Override
    public void setEnvironment(Environment env) {
        this.env = env;
        this.propertyResolver = new RelaxedPropertyResolver(env, "spring.datasource.");
    }

    @Bean(destroyMethod = "shutdown")
    @ConditionalOnMissingClass(name = "uk.co.config.HerokuDatabaseConfiguration")
    @Profile("!" + Constants.SPRING_PROFILE_CLOUD)
    public DataSource dataSource() {
        log.debug("Configuring Datasource");
        if (propertyResolver.getProperty("url") == null && propertyResolver.getProperty("databaseName") == null) {
            log.error("Your database connection pool configuration is incorrect! The application" +
                    "cannot start. Please check your Spring profile, current profiles are: {}",
                    Arrays.toString(env.getActiveProfiles()));

            throw new ApplicationContextException("Database connection pool is not configured correctly");
        }
        HikariConfig config = new HikariConfig();
        config.setDataSourceClassName(propertyResolver.getProperty("dataSourceClassName"));
        if (propertyResolver.getProperty("url") == null || "".equals(propertyResolver.getProperty("url"))) {
            config.addDataSourceProperty("databaseName", propertyResolver.getProperty("databaseName"));
            config.addDataSourceProperty("serverName", propertyResolver.getProperty("serverName"));
        } else {
            config.addDataSourceProperty("url", propertyResolver.getProperty("url"));
        }
        config.addDataSourceProperty("user", propertyResolver.getProperty("username"));
        config.addDataSourceProperty("password", propertyResolver.getProperty("password"));

        if (metricRegistry != null) {
            config.setMetricRegistry(metricRegistry);
        }
        return new HikariDataSource(config);
    }

    @Bean
    public SpringLiquibase liquibase(DataSource dataSource) {
        SpringLiquibase liquibase = new SpringLiquibase();
        liquibase.setDataSource(dataSource);
        liquibase.setChangeLog("classpath:config/liquibase/master.xml");
        liquibase.setContexts("development, production");
        if (env.acceptsProfiles(Constants.SPRING_PROFILE_FAST)) {
            if ("org.h2.jdbcx.JdbcDataSource".equals(propertyResolver.getProperty("dataSourceClassName"))) {
                liquibase.setShouldRun(true);
                log.warn("Using '{}' profile with H2 database in memory is not optimal, you should consider switching to" +
                    " MySQL or Postgresql to avoid rebuilding your database upon each start.", Constants.SPRING_PROFILE_FAST);
            } else {
                liquibase.setShouldRun(false);
            }
        } else {
            log.debug("Configuring Liquibase");
        }
        return liquibase;
    }

    @Bean
    public Hibernate4Module hibernate4Module() {
        return new Hibernate4Module();
    }

    @Bean
    public EntityManagerFactory entityManagerFactory() {

      HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
      vendorAdapter.setGenerateDdl(true);

      LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
      factory.setJpaVendorAdapter(vendorAdapter);
      factory.setPackagesToScan("uk.co.repository");
      factory.setDataSource(dataSource());
      factory.afterPropertiesSet();

      return factory.getObject();
    }
}

众所周知的事实是液体碱将所有变更日志写入名为的表中数据库变更日志在您的数据库中为:

所有 Liquibase 更改的根源是databaseChangeLog 文件。

当我遇到类似的错误时,我通过更改中的校验和值手动解决了它数据库变更日志我的数据库中的表。您可以通过在数据库中运行以下 SQL 查询来解决该问题:

UPDATE `databasechangelog` SET `MD5SUM`=`7:bde7b076d47aefe8278d126cde26b172` WHERE `ID`=`00000000000001`;

另一种解决方法

截断databasechangelog桌子。添加无液体碱在适当的地方pom.xml文件如下:

<properties>
    <spring.profiles.active>local,no-liquibase</spring.profiles.active>
</properties>

然后运行mvn (or mvnw,根据您的项目设置),应用程序将成功启动!

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

创建类路径资源中定义的名为“liquibase”的 bean 时出错.../config/DatabaseConfiguration.class 的相关文章

随机推荐

  • 如何读取注册表项的默认值

    我有一个 Delphi XE2 项目来使用注册表项进行某些操作 所以我定义了以下代码 procedure TMainForm BitBtn01Click Sender TObject var RegistryEntry TRegistry
  • R 未获取用户库

    我有一个带 R 3 6 0 的 Fedora 30 系统 用户库设置在Renviron就像这个 R LIBS USER R LIBS USER R x86 64 redhat linux gnu library 3 6 事实上 它出现在交互
  • NFC标签唯一ID

    我正在开发一个包括 NFC 标签和 Android 手机的系统 使用 NFC 标签的唯一 ID 但不知道4种NFC标签之间有什么区别 我发现了这个 兼容 NFC 的标签可以采用以下技术 标准 他们每个人都有不同的 ID 概念 NFC Tag
  • SoundEffect 和 SoundEffectInstance 类之间的区别

    就像有问题一样 我不明白使用这些类有什么区别 每个类别的优点和局限性是什么 我读了很多教程 但仍然无法决定我应该做什么 为了让事情更清楚 我得到了 AudioModule AudioEmitterComponent 和 AudioListe
  • 如何从spark管道逻辑模型中提取变量权重?

    我目前正在尝试学习 Spark Pipeline Spark 1 6 0 我将数据集 训练和测试 导入为 oas sql DataFrame 对象 执行以下代码后 生成的模型是oas ml tuning CrossValidatorMode
  • 如何在 Rails 2.3.5 中从模型渲染部分

    我有一个 Rails 2 3 5 应用程序 我试图从模型中渲染几个部分 我知道 我知道 我不应该这样做 我这样做的原因是我将 Comet 服务器 APE 集成到我的 Rails 应用程序中 并且需要根据模型的事件 例如 after crea
  • 方案如何返回多个值?

    我注意到几乎所有方案函数只能返回一个列表作为输出 下面 我想返回邻居的所有相邻节点的多个值 define neighbors l w if and 1 l 1 w list and l 1 w and 1 l w how to output
  • 如果指定了多个存储库,install.packages 的行为是什么?

    从文档中并不清楚如果在 install packages 中指定了多个存储库会出现什么行为 我的直觉告诉我 它将尝试第一个存储库 如果找不到包 它将尝试第二个存储库 依此类推 不幸的是 情况似乎并非如此 我看到的是 只尝试了第一个 并返回错
  • Bash 脚本 - 迭代 find 的输出

    我有一个 bash 脚本 其中需要迭代 find 命令输出的每一行 但似乎我正在迭代 find 命令中的每个单词 以空格分隔 到目前为止我的脚本看起来像这样 folders find maxdepth 1 type d for i in f
  • 仅使用 SQL 中的 MAX 函数更新重复行

    我有一张这样的桌子 假设为了举例 NAME是一个唯一的标识符 NAME AGE VALUE Jack Under 65 3 Jack 66 74 5 John 66 74 7 John Over 75 9 Gill 25 35 11 Som
  • SQLite3 中的“预准备”语句?

    在具有固定查询集的内存受限嵌入式系统中使用 SQLite 如果可以 预先准备 查询 则似乎可以节省代码和数据 也就是说 准备好的语句是由 相当于 sqlite3 prepare v2 在build运行时只需要调用 bind step 等 引
  • MP4 到 DASH(bash 脚本)

    我有一个网站 用户可以在其中上传视频文件 我想使用 DASH 流式传输所有内容以获得自适应比特率流式传输 因此 我编写了一个 bash 脚本 由 cron 运行 将所有 mp4 文件转换为 DASH 但它无法正常工作 出了什么问题 例如 使
  • Python:在同一遍中计数和替换正则表达式?

    我可以全局替换正则表达式re sub 我可以计算匹配项 for match in re finditer count 有没有办法将这两者结合起来 以便我可以计算替换次数 而无需对源字符串进行两次传递 注意 我对替换是否匹配不感兴趣 我感兴趣
  • 如何从字符串中删除除字母、数字、空格、感叹号和问号之外的所有内容?

    如何删除除以下内容之外的所有内容 字符串中的字母 数字 空格 感叹号 问号 该方法支持国际语言 UTF 8 非常重要 您可以使用正则表达式 myString replace w s g 这将替换除单词字符 空格 感叹号或问题之外的所有内容
  • Javascript/jQuery 变量未给出预期值

    和我之前的其他人一样 我也在 Javascript 的范围内苦苦挣扎 那并试图阅读该死的东西 我已经检查了关于这个问题的一些先前的线程 但我似乎无法让它们正确地应用于我的问题 在下面的示例中 我想操纵中的值tagsArr数组 一旦数组已完全
  • 如何制作像图像中那样精确的 CSS3 线性渐变?

    For example this is gradient which I want to make in CSS3 我可以使用 1 px 图像剪切并在 x 轴上重复 就像我们之前所做的那样 但现在如果我想使用 CSS3 制作同样精确的渐变
  • 如何使用 Selenium Webdriver C# 替换 innerHTML 代码?

    HTML 代码
  • C++ 中的函数指针与仿函数

    使用函子和函数指针有什么区别 例如 Functor struct add x int x add x int y x y int operator int y return x y Function int func int x retur
  • Excel - 根据选择创建图表的宏

    我想就以下问题寻求您的帮助 因为我必须创建大量图表 所以我想要一个宏来根据我的选择插入图表 由于我对 VBA 没有任何了解 但现在需要它 至少现在 我真的应该自己学习使用它 我将感谢您的帮助 基本上 我需要知道如何调整我记录的代码 以便根据
  • 创建类路径资源中定义的名为“liquibase”的 bean 时出错.../config/DatabaseConfiguration.class

    在我的 jHipster 项目上启动嵌入式 Tomcat 时 我遇到了这个恼人的错误 花了很多时间试图解决它 但无法弄清楚为什么会发生 它是在主要代表更新项目后开始发生的 但我也实现了自定义存储库 堆栈跟踪 DEBUG uk co conf