无法从 Spring Boot 应用程序运行 flyway 脚本,数据库为 docker 容器中的 Mysql

     2023-02-26     112

关键词:

【中文标题】无法从 Spring Boot 应用程序运行 flyway 脚本,数据库为 docker 容器中的 Mysql【英文标题】:Unable to run the flyway scripts from Spring Boot application with database as Mysql in docker container 【发布时间】:2018-11-10 14:55:30 【问题描述】:

我有一个 spring boot 应用程序,它有很多 flyway 脚本。一旦启动应用程序启动,此脚本将自动运行。他们在没有 docker 的情况下正常运行。当我将此应用程序放入 docker 容器中时 应用程序.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

db/migration/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)
)

我的应用程序-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 build 之后,我正在像这样将我的 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)
)

谁能帮助解决这个问题。

【问题讨论】:

【参考方案1】:
Message    : Schema "SYNFIOO_POC" not found; SQL statement:
CREATE TABLE synfioo_poc.Binary_Object (
...

看起来V0001__R001_Create_schema.sql 中引用的synfioo_poc 架构/数据库在mysql-docker-container 实例中不存在。

如有必要,请尝试将 createDatabaseIfNotExist=true 添加到 jdbc url 以便 mysql 自动创建它:

url:jdbc:mysql://mysql-docker-container:3306/synfioo_poc?useSSL=false&createDatabaseIfNotExist=true

【讨论】:

无法从命令提示符将 Spring Boot 应用程序作为可运行 jar 运行

】无法从命令提示符将SpringBoot应用程序作为可运行jar运行【英文标题】:NotablerunSpringbootapplicationasrunnablejarfromcommandprompt【发布时间】:2017-06-2821:53:03【问题描述】:我可以从我的Eclipse中运行应用程序,但是当我创建jar时尝试从... 查看详情

无法从通过intellij运行的spring boot应用程序连接到我在docker上运行的kafka

】无法从通过intellij运行的springboot应用程序连接到我在docker上运行的kafka【英文标题】:Can\'tconnecttomykafkarunningondockerfromspringbootapplicationrunningviaintellij【发布时间】:2022-01-0416:48:43【问题描述】:我有一个包含Kafka、zookeeper和spring... 查看详情

无法从 Spring Boot 应用程序运行 flyway 脚本,数据库为 docker 容器中的 Mysql

】无法从SpringBoot应用程序运行flyway脚本,数据库为docker容器中的Mysql【英文标题】:UnabletoruntheflywayscriptsfromSpringBootapplicationwithdatabaseasMysqlindockercontainer【发布时间】:2018-11-1014:55:30【问题描述】:我有一个springboot应用程序,它... 查看详情

无法从 JUnit 中的 Spring Boot 读取应用程序属性?

】无法从JUnit中的SpringBoot读取应用程序属性?【英文标题】:NotabletoreadapplicationpropertiesfromSpringBootinJUnit?【发布时间】:2017-06-2613:16:32【问题描述】:我有一个JUnit测试,我想针对REST服务运行该服务,该服务已经在我的机器上的... 查看详情

在 Docker 容器内运行 Spring Boot 应用程序,无法连接 MySQL

】在Docker容器内运行SpringBoot应用程序,无法连接MySQL【英文标题】:RunningSpringBootappinsideDockercontainer,unabletoconnectMySQL【发布时间】:2015-11-1901:57:45【问题描述】:我正在尝试学习Docker,并创建了一个运行MySQL服务器的容器。它工... 查看详情

Gradle Spring Boot 应用程序无法从 Json 文件中提取数据

】GradleSpringBoot应用程序无法从Json文件中提取数据【英文标题】:GradleSpringBootApplicationFailedtoExtractDatafromJsonfile【发布时间】:2022-01-2011:36:01【问题描述】:我创建了带有springboot依赖项的Gradle项目,这是一个restapi。我默认使用netb... 查看详情

无法从 spring-boot 应用程序中调出 swagger-ui

】无法从spring-boot应用程序中调出swagger-ui【英文标题】:Unabletobringupswagger-uifromspring-bootapplication【发布时间】:2015-11-1813:58:03【问题描述】:我有一个使用嵌入式tomcat服务器运行的springboot应用程序。我在将springfox-swagger与应用程... 查看详情

无法使用 thymeleaf 运行 Spring Boot 应用程序

】无法使用thymeleaf运行SpringBoot应用程序【英文标题】:Unabletorunspringbootapplicationwiththymeleaf【发布时间】:2018-07-0203:46:09【问题描述】:我的主要应用类:packagecom.sopra.springBoot;importorg.springframework.boot.SpringApplication;importorg.springframe 查看详情

无法运行 Spring Boot 应用程序,出现 OptimisticLockException

】无法运行SpringBoot应用程序,出现OptimisticLockException【英文标题】:Unabletorunspringbootapplication,gettingOptimisticLockException【发布时间】:2018-08-2502:10:23【问题描述】:我遇到错误错误:启动ApplicationContext时出错。显示自动配置报告启... 查看详情

无法运行 Spring Boot 应用程序?

】无法运行SpringBoot应用程序?【英文标题】:Cantrunspringbootapplication?【发布时间】:2020-10-0305:13:19【问题描述】:我正在与一个团队一起完成一项任务。我的团队决定为应用程序使用springboot。但是由于某种原因,每当我运行应... 查看详情

为啥 spring-boot 应用程序无法在 AWS 中运行,但在本地运行良好?

】为啥spring-boot应用程序无法在AWS中运行,但在本地运行良好?【英文标题】:Whyspring-bootappisnotworkinginAWSbutworksfineinlocal?为什么spring-boot应用程序无法在AWS中运行,但在本地运行良好?【发布时间】:2020-12-1817:19:26【问题描述】... 查看详情

无法使用 SSL 运行 Spring Boot 应用程序

】无法使用SSL运行SpringBoot应用程序【英文标题】:UnabletorunSpringbootapplicationusingSSL【发布时间】:2020-02-2214:25:26【问题描述】:我无法使用https运行SpringBoot应用程序。我知道Springboot使用的是嵌入式tomcat服务器下面是堆栈跟踪org.ap... 查看详情

无法从同一网络中的另一台计算机访问在我的计算机中运行的 SPRING BOOT 应用程序的 REST API

...络中的另一台计算机访问在我的计算机中运行的SPRINGBOOT应用程序的RESTAPI【英文标题】:UnabletoaccessRESTAPIofaSPRINGBOOTApplicationwhichisrunninginmycomputer,fromanothercomputerinsamenetwork【发布时间】:2018-04-0214:16:56【问题描述】:我在SpringBoot应... 查看详情

Spring Boot无法使用intellij idea启动应用程序

】SpringBoot无法使用intellijidea启动应用程序【英文标题】:Springbootfailingtostartapplicationusingintellijidea【发布时间】:2016-03-2917:10:53【问题描述】:我尝试从spring主页“https://spring.io/guides/gs/rest-service/”模拟RESTfulWebService。Gradle编译工... 查看详情

无法使用 @EnableWebMvc 配置运行 SPRING BOOT 应用程序

】无法使用@EnableWebMvc配置运行SPRINGBOOT应用程序【英文标题】:Can\'truntheSPRINGBOOTapplicationwith@EnableWebMvcconfiguration【发布时间】:2018-07-2104:15:26【问题描述】:我是SpringBoot新手,我对学习这项技术非常感兴趣。这是问题所在,我得... 查看详情

无法使用命令行参数启动 Spring Boot 应用程序

】无法使用命令行参数启动SpringBoot应用程序【英文标题】:Unabletousecommandlineargumentstostartspringbootaplication【发布时间】:2017-03-0821:37:39【问题描述】:我的系统上设置了以下内容。Ubuntu16.04Gradle3.0Java1.8.0_91springBootVersion:1.4.0.RELEAS... 查看详情

无法使用命令行参数启动 Spring Boot 应用程序

】无法使用命令行参数启动SpringBoot应用程序【英文标题】:Unabletousecommandlineargumentstostartspringbootaplication【发布时间】:2017-03-0821:37:39【问题描述】:我的系统上设置了以下内容。Ubuntu16.04Gradle3.0Java1.8.0_91springBootVersion:1.4.0.RELEAS... 查看详情

从“openjdk:8-jdk-alpine”为 Spring Boot 应用程序构建 docker 映像时无法运行“RUN ./mvnw dependency:go-offline -B”

】从“openjdk:8-jdk-alpine”为SpringBoot应用程序构建docker映像时无法运行“RUN./mvnwdependency:go-offline-B”【英文标题】:Unabletorun\'RUN./mvnwdependency:go-offline-B\'whenbuildingdockerimagefrom"openjdk:8-jdk-alpine"forSpringBootapp【发布 查看详情