我有春季启动应用程序,它有很多飞路脚本。一旦启动应用程序启动,此脚本将自动运行。它们在没有泊坞的情况下正常运行。当我把这个应用程序放在docker容器中时 application.yml
server:
port:8080
context-path:/tms-server
http:
mappers:
jsonPrettyPrint:true
security:
basic:
enabled:false
cors:
enabled:true
flyway:
enabled:true
clean-on-validation-error:false
validate-on-migrate:false
url:jdbc:mysql://mysql-docker-container:3306/synfioo_poc?useSSL=false
user:app_user
password:test123
schemas:synfioo_poc
locations:db/migration/mysql
spring:
profiles:
active:mysql
flyway Sql文件位于classpath:db/migration/mysql
分贝/迁移/ MySQL的/ V0001__R001_Create_schema.sql:
CREATE TABLE synfioo_poc.Binary_Object (
id BIGINT NOT NULL AUTO_INCREMENT,
modification_counter INTEGER NOT NULL,
data BLOB(2147483647),
size BIGINT NOT NULL,
mime_Type VARCHAR(255),
PRIMARY KEY (ID)
)
我的application-mysql.yml看起来像
spring:
jpa:
database:mysql
database-platform:org.hibernate.dialect.MySQL5Dialect
datasource:
url:jdbc:mysql://mysql-docker-container:3306/synfioo_poc?useSSL=false
username:app_user
password:test123
driver-class-name:com.mysql.jdbc.Driver
在docker构建之后,我将我的Spring Boot与Mysql Db链接起来 假设我已经正确创建了mysql图像并且它运行能够从mysql客户端创建表但是flyway脚本没有从java程序运行 还正确创建了docker文件
docker run -t --name synfioo-poc-container --link mysql-docker-container:mysql -p 8080:8080 docker-synfioo-core:latest
例外:
2018-05-31 13:28:45.746 INFO 1 --- [ main] o.f.core.internal.util.VersionPrinter : Flyway 3.2.1 by Boxfuse
2018-05-31 13:28:46.783 INFO 1 --- [ main] o.f.c.i.dbsupport.DbSupportFactory : Database: jdbc:h2:mem:testdb (H2 1.4)
2018-05-31 13:28:47.457 INFO 1 --- [ main] o.f.core.internal.command.DbValidate : Validated 18 migrations (execution time 00:00.506s)
2018-05-31 13:28:47.502 INFO 1 --- [ main] o.f.c.i.metadatatable.MetaDataTableImpl : Creating Metadata table: "PUBLIC"."schema_version"
2018-05-31 13:28:47.609 INFO 1 --- [ main] o.f.core.internal.command.DbMigrate : Current version of schema "PUBLIC": << Empty Schema >>
2018-05-31 13:28:47.615 INFO 1 --- [ main] o.f.core.internal.command.DbMigrate : Migrating schema "PUBLIC" to version 0001 - R001 Create schema
2018-05-31 13:28:47.638 ERROR 1 --- [ main] o.f.core.internal.command.DbMigrate : Migration of schema "PUBLIC" to version 0001 failed! Please restore back
ups and roll back database and code!
2018-05-31 13:28:47.670 WARN 1 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh
attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'beansBatchConfig': Unsatisfied dependency expressed through me
thod 'setTransactionManager' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager'
defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Initialization of bean failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoc
onfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.internal.dbsupport.FlywaySqlScriptException:
Migration V0001__R001_Create_schema.sql failed
----------------------------------------------
SQL State : 90079
Error Code : 90079
Message : Schema "SYNFIOO_POC" not found; SQL statement:
CREATE TABLE synfioo_poc.Binary_Object (
id BIGINT NOT NULL AUTO_INCREMENT,
modification_counter INTEGER NOT NULL,
data BLOB(2147483647),
size BIGINT NOT NULL,
mime_Type VARCHAR(255),
PRIMARY KEY (ID)
) [90079-193]
Location : db/migration/mysql/V0001__R001_Create_schema.sql (/file:/synfioo-core-0.0.1-SNAPSHOT.jar!/db/migration/mysql/V0001__R001_Create_schema.sq
Line : 8
Statement : CREATE TABLE synfioo_poc.Binary_Object (
id BIGINT NOT NULL AUTO_INCREMENT,
modification_counter INTEGER NOT NULL,
data BLOB(2147483647),
size BIGINT NOT NULL,
mime_Type VARCHAR(255),
PRIMARY KEY (ID)
)
任何人都可以帮助解决这个问题。
答案 0 :(得分:0)
Message : Schema "SYNFIOO_POC" not found; SQL statement:
CREATE TABLE synfioo_poc.Binary_Object (
...
synfioo_poc
实例中不存在V0001__R001_Create_schema.sql
中引用的mysql-docker-container
架构/数据库。
尝试将createDatabaseIfNotExist=true
添加到mysql的jdbc网址,以便在必要时自动创建它:
url:jdbc:mysql://mysql-docker-container:3306/synfioo_poc?useSSL=false&createDatabaseIfNotExist=true