SpringBoot - Flyway - JPA 集成 - 创建名称为“flywayInitializer”的 bean 时出错 - information_schema 中的未知表“事件”
Posted
技术标签:
【中文标题】SpringBoot - Flyway - JPA 集成 - 创建名称为“flywayInitializer”的 bean 时出错 - information_schema 中的未知表“事件”【英文标题】:SpringBoot - Flyway - JPA integration -- Error creating bean with name 'flywayInitializer' - Unknown table 'events' in information_schema 【发布时间】:2018-07-23 15:30:59 【问题描述】:我正在使用JPA
和mysql
作为数据库将我的Spring Boot Application
与Flyway
集成。
Git 源 - https://github.com/codethinker09/codeExamples.git
项目 - flywaydemo
application.properties
spring.datasource.url=jdbc:mysql://localhost:3306/spring-jpa-flyway?autoReconnect=true&zeroDateTimeBehavior=convertToNull
spring.jpa.hibernate.ddl-auto=validate
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.datasource.username = root
spring.datasource.password = root123
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
flyway.password = root123
flyway.url= jdbc:mysql://localhost:3306/spring-flyway?autoReconnect=true&zeroDateTimeBehavior=convertToNull
flyway.user = root
flyway.enabled=true
分级
buildscript
ext
springBootVersion = '1.5.10.RELEASE'
repositories
mavenCentral()
dependencies
classpath("org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion")
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
group = 'com.boot.flyway'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories
mavenCentral()
dependencies
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-data-rest')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.flywaydb:flyway-core')
runtime('mysql:mysql-connector-java')
testCompile('org.springframework.boot:spring-boot-starter-test')
我已经在 MySql 中手动创建了 2 个数据库 数据库表快照 -
项目结构 -
例外
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.flywa
ydb.core.api.FlywayException: Unable to check whether schema `spring-flyway` is empty
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:296) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1080) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:857) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at com.boot.flyway.flywaydemo.FlywaydemoApplication.main(FlywaydemoApplication.java:10) [main/:na]
Caused by: org.flywaydb.core.api.FlywayException: Unable to check whether schema `spring-flyway` is empty
at org.flywaydb.core.internal.dbsupport.Schema.empty(Schema.java:95) ~[flyway-core-3.2.1.jar:na]
at org.flywaydb.core.Flyway$1.execute(Flyway.java:1021) ~[flyway-core-3.2.1.jar:na]
at org.flywaydb.core.Flyway$1.execute(Flyway.java:1006) ~[flyway-core-3.2.1.jar:na]
at org.flywaydb.core.Flyway.execute(Flyway.java:1418) ~[flyway-core-3.2.1.jar:na]
at org.flywaydb.core.Flyway.migrate(Flyway.java:1006) ~[flyway-core-3.2.1.jar:na]
at org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitializer.java:66) ~[spring-boot-autoconfigure-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
... 18 common frames omitted
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown table 'events' in information_schema
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_121]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_121]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_121]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_121]
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) ~[mysql-connector-java-5.1.45.jar:5.1.45]
at com.mysql.jdbc.Util.getInstance(Util.java:408) ~[mysql-connector-java-5.1.45.jar:5.1.45]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:944) ~[mysql-connector-java-5.1.45.jar:5.1.45]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3973) ~[mysql-connector-java-5.1.45.jar:5.1.45]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3909) ~[mysql-connector-java-5.1.45.jar:5.1.45]
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2527) ~[mysql-connector-java-5.1.45.jar:5.1.45]
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2680) ~[mysql-connector-java-5.1.45.jar:5.1.45]
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2484) ~[mysql-connector-java-5.1.45.jar:5.1.45]
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1858) ~[mysql-connector-java-5.1.45.jar:5.1.45]
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1966) ~[mysql-connector-java-5.1.45.jar:5.1.45]
at org.flywaydb.core.internal.dbsupport.JdbcTemplate.queryForInt(JdbcTemplate.java:156) ~[flyway-core-3.2.1.jar:na]
at org.flywaydb.core.internal.dbsupport.mysql.MySQLSchema.doEmpty(MySQLSchema.java:49) ~[flyway-core-3.2.1.jar:na]
at org.flywaydb.core.internal.dbsupport.Schema.empty(Schema.java:93) ~[flyway-core-3.2.1.jar:na]
... 25 common frames omitted
我无法解决此异常,请到处搜索。我是否缺少与 Flyway 相关的任何配置。
【问题讨论】:
你使用什么版本的 MySQL? @JánHalaša 版本为mysql-connector-java
是5.1.45
,安装的mysql 是'5.0.45-community-nt'
,flyway-core 是3.2.1
【参考方案1】:
您使用的mysql-connector
比您的 MySQL 服务器更新,并且连接器希望它具有 MySQL 5.1 中引入的事件功能。这就是它找不到events
表的原因:
Unknown table 'events' in information_schema
您可能应该升级您的 MySQL 服务器(5.0 版非常旧)。正如 Axel Fontaine 在他的回答中提到的,Flyway 需要 MySQL 5.1 或更高版本。
【讨论】:
【参考方案2】:作为documented on the Flyway website,Flyway 仅支持 MySQL 5.1 及更新版本。
【讨论】:
以上是关于SpringBoot - Flyway - JPA 集成 - 创建名称为“flywayInitializer”的 bean 时出错 - information_schema 中的未知表“事件”的主要内容,如果未能解决你的问题,请参考以下文章
Spring Data JPA / Flyway 转义双引号