Spring Boot版本升级-在aws elastic beanstalk中部署时出现mysql错误
Posted
技术标签:
【中文标题】Spring Boot版本升级-在aws elastic beanstalk中部署时出现mysql错误【英文标题】:Springboot version upgrade - my sql error while deploying in aws elastic beanstalk 【发布时间】:2021-01-22 09:44:25 【问题描述】:我们正在尝试通过 build.gradle 依赖升级我们的项目:
build.gradle 文件:
buildscript
ext
springBootVersion = '2.3.3.RELEASE'
repositories
mavenCentral()
maven
url "https://plugins.gradle.org/m2/"
dependencies
classpath("org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion")
classpath('se.transmode.gradle:gradle-docker:1.2')
group = 'testing'
version = '0.0.1-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: "jacoco"
apply from: 'docker.gradle'
sourceCompatibility = 1.8
bootJar
launchScript()
repositories
mavenCentral()
dependencies
implementation 'org.springframework.boot:spring-boot-starter-actuator'
compile ('org.springframework.boot:spring-boot-starter-data-jpa')
compile ('org.springframework.boot:spring-boot-starter-web')
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.flywaydb:flyway-core'
runtime 'mysql:mysql-connector-java:5.1.47'
implementation 'com.zaxxer:HikariCP'
annotationProcessor('org.hibernate:hibernate-jpamodelgen')
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.mobile:spring-mobile-device:1.1.5.RELEASE'
implementation 'io.jsonwebtoken:jjwt-api:0.10.5'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.10.5'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.10.5'
implementation 'com.amazonaws:aws-java-sdk-s3:1.11.136'
implementation 'org.springframework.boot:spring-boot-starter-mail'
implementation 'org.springframework.boot:spring-boot-starter-freemarker'
implementation 'org.springframework.boot:spring-boot-starter-tomcat'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
testCompile('org.springframework.boot:spring-boot-starter-test')
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
testImplementation('org.springframework.security:spring-security-test')
compile 'com.h2database:h2'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
implementation 'org.apache.commons:commons-lang3'
implementation 'com.univocity:univocity-parsers:2.7.6'
implementation 'org.quartz-scheduler:quartz:2.2.1'
implementation 'org.apache.poi:poi:3.17'
implementation 'org.apache.poi:poi-ooxml:3.17'
test.reports.junitXml.setDestination(file("$buildDir/test-results"))
jacocoTestReport
reports
html.destination file("$buildDir/jacocoHtml")
sourceSets
main
java
srcDirs += "src/jpaModelgen/java"
compileJava
options.compilerArgs += ['-AaddGenerationDate=true'] // Specific to Hibernate JPA meta model generation processor.
options.annotationProcessorGeneratedSourcesDirectory = file("src/jpaModelgen/java")
application.properties 文件:
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.database=mysql
spring.data.jpa.repositories.enabled=true
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.datasource.url= jdbc:mysql://MyDB:3306/myschema
spring.datasource.username= testing
spring.datasource.password= root
spring-boot 从版本1.5.7
到2.3.3
从版本Gradle-4.8-all
升级到Gradle-6.4.1-all
当我们在本地运行应用程序时,我们会在日志中得到以下输出,
o.f.c.internal.database.DatabaseFactory : Database: jdbc:mysql://MyDB:3306/myschema (MySQL 5.7)
当我们将相同的代码部署到AWS Elastic Beanstalk
时,
我们收到以下错误:
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.internal.command.DbMigrate$FlywayMigrateException:
Migration V3__Sequence_Table.sql failed
---------------------------------------
SQL State : 42001
Error Code : 42001
Message : Syntax error in SQL statement "DELIMITER[*]
JDBC
连接URL
现在已更改如下,
o.f.c.internal.database.DatabaseFactory : Database: jdbc:h2:mem:testdb (H2 1.4)
这是导致上述flyway
迁移错误还是Docker
版本错误的原因?
【问题讨论】:
【参考方案1】:问题:
jar
文件的Run
命令是这个项目的问题`
Dspring.config.location=run.properties
这个逗号只执行run.properties
解决方案:
代替上面的run
命令,我已经为jar
文件尝试了这个run
命令
Dspring.config.additional-location=run.properties
效果很好
【讨论】:
以上是关于Spring Boot版本升级-在aws elastic beanstalk中部署时出现mysql错误的主要内容,如果未能解决你的问题,请参考以下文章