英文:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer'
问题
以下是翻译好的内容:
在我的学习中,我遇到了关于 Flyway 的问题。我根据视频课程开始了项目,但在开始后,我注意到 Flyway 和 Spring 的版本已过时,于是在 pom.xml 中放入了另一个版本。我删除了创建的 category 表,然后 Flyway 显示了以下错误,当我尝试上传项目时:
org.springframework.beans.factory.BeanCreationException: 在类路径资源 [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class] 中定义的名为 'flywayInitializer' 的 Bean 创建出错:初始化方法的调用失败;嵌套异常是 org.flywaydb.core.api.FlywayException: 验证失败:
迁移版本 01 的校验和不匹配
-> 已应用于数据库:1894708545
-> 本地解决:-2070596035
Pom.xml 修改前:
<!-- 在此插入原 pom.xml 的内容 -->
Pom.xml 修改后:
<!-- 在此插入修改后的 pom.xml 的内容 -->
Myscript(我的脚本):
CREATE TABLE categoria (
id BIGINT(20) PRIMARY KEY AUTO_INCREMENT,
nome VARCHAR(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO categoria (nome) VALUES ('Lazer');
INSERT INTO categoria (nome) VALUES ('Alimentação');
INSERT INTO categoria (nome) VALUES ('Supermercado');
INSERT INTO categoria (nome) VALUES ('Farmácia');
INSERT INTO categoria (nome) VALUES ('Outros');
数据库中尚未创建表,并且 schema_version 中也没有记录,因为我也将其删除。为什么会出现错误?有人可以告诉我吗?
英文:
In my studies I had a problem with the flyway, I started the project according to the video lesson, but after starting I noticed that the versions of flyway and spring were out of date and put another version in the pom.xml Drope the created category table and the version e scheme flyway shows me this error when I try to upload the project.
> org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path
> resource
> [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]:
> Invocation of init method failed; nested exception is
> org.flywaydb.core.api.FlywayException: Validate failed:
>
> Migration checksum mismatch for migration version 01
> -> Applied to database : 1894708545
> -> Resolved locally : -2070596035
Pom.xml before:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.algaworks.algamoney-api</groupId>
<artifactId>algamoney-api</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>algamoney-api</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>3.2.1</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Pom.xml after:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.RELEASE</version>
<!-- <packaging>jar</packaging> -->
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.algaworks.algamoney-api</groupId>
<artifactId>algamoney-api</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>algamoney-api</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>6.4.4</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</proje
ct>
Myscript:
CREATE table categoria(
id BIGINT(20) PRIMARY KEY AUTO_INCREMENT,
nome VARCHAR(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO categoria (nome) values ('Lazer');
INSERT INTO categoria (nome) values ('Alimentação');
INSERT INTO categoria (nome) values ('Supermercado');
INSERT INTO categoria (nome) values ('Farmácia');
INSERT INTO categoria (nome) values ('Outros');
There is no table in the database yet created and no record in schema_version because I also dropped it. Why the error? Can anyone tell me?
答案1
得分: 1
如果您查看Flyway的发布文档,可以看到从Flyway 4升级到5/6时,schema_version表已更改为flyway_schema_history。
此外,用于计算校验和的算法也发生了变化:
版本3 -
通过字节执行crc32:
bytes = resource.loadAsBytes()
...
crc32.update(bytes);
版本5(非逐字复制) -
通过行执行crc32(忽略CR/LF,并使用UTF-8编码):
BufferedReader bufferedReader = new BufferedReader(new StringReader(resource.loadAsString(configuration.getEncoding())));
[...]
while ((line = bufferedReader.readLine()) != null) {
crc32.update(line.getBytes("UTF-8"));
}
Flyway在v6中用于计算校验和的类名为org.flywaydb.core.internal.resolver.ChecksumCalculator
第一个更改(关于表格)可以通过使用以下属性来解决:
flyway.table=schema_version
第二个更改(校验和算法)可以通过在调用迁移之前使用flyway repair来解决(可以通过命令行或代码执行):
Flyway flyway = fluentConfig.schemas(schemaName).load();
flyway.repair();
flyway.migrate();
英文:
If you check the release documentation of Flyway, it says, that from Flyway 4 to 5/6 the schema_version table has changed to flyway_schema_history.
Also the algorithm to calculate checksum has changed:
version 3 -
crc32 over bytes:
bytes = resource.loadAsBytes()
...
crc32.update(bytes);
version 5 (not a verbatim copy) -
crc32 over lines (ignoring CR/LF, and using UTF-8 encoding):
BufferedReader bufferedReader = new BufferedReader(new StringReader(resource.loadAsString(configuration.getEncoding())));
[...]
while ((line = bufferedReader.readLine()) != null) {
crc32.update(line.getBytes("UTF-8"));
}
The class name which flyway uses for checksum calculation in v6 is org.flywaydb.core.internal.resolver.ChecksumCalculator
The first change (about table) can be tackled by using the following property:
flyway.table=schema_version
The second change( checksum algorithm) can be tackled by using flyway repair before calling migrate (either through commandline or through code)
Flyway flyway = fluentConfig.schemas(schemaName).load();
flyway.repair();
flyway.migrate();
答案2
得分: 0
以下是您的翻译内容:
我的POM:
这是我的pom.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.RELEASE</version>
<!-- <packaging>jar</packaging> -->
<relativePath /> <!-- 从仓库中查找父级 -->
</parent>
<groupId>com.algaworks.algamoney-api</groupId>
<artifactId>algamoney-api</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>algamoney-api</name>
<description>Spring Boot演示项目</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>6.4.4</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
注意:这是您提供的内容的中文翻译,其中代码部分没有进行翻译。
英文:
My pom:
This is my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.RELEASE</version>
<!-- <packaging>jar</packaging> -->
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.algaworks.algamoney-api</groupId>
<artifactId>algamoney-api</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>algamoney-api</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>6.4.4</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论