问题描述
如果我使用硬编码而不将其外部化 password=ravi@123
而不是以下格式,我可以连接云 MysqL 服务器,但目前我使用以下格式以使用环境变量中的值,但它失败了在弹簧靴。主机名是我们的 Azure 托管 MysqL 服务器主机。
我在谷歌上搜索了足够多的 StackOverflow 解决方案并尝试了多个其他选项以及添加到连接字符串 URL 的字符编码,但仍然没有运气!
characterEncoding=UTF-8
url=jdbc:MysqL://${MysqL_host:hostname}:${MysqL_port:3306}/ravidb?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneshift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&useSSL=false&autoReconnect=true&allowPublicKeyRetrieval=true
有人能帮我理解我错过了什么吗?考虑到我无法修改用户名或密码,可能的解决方法是什么?
application.yaml
spring:
profiles:
active: development
jackson:
serialization:
fail-on-empty-beans: false
datasource:
driver-class-name: org.mariadb.jdbc.Driver
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:mariadb://${MysqL_host:hostname}:${MysqL_port:3306}/ravidb?useUnicode=true&useJDBCCompliantTimezoneshift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&useSSL=false&autoReconnect=true&allowPublicKeyRetrieval=true
username: ${MysqL_user:ravi@ravidb}
password: ${MysqL_password:ravi@123}
hikari:
auto-commit: true
connection-timeout: 20000
idle-timeout: 300000
max-lifetime: 1200000
maximum-pool-size: 12
minimum-idle: 5
jpa:
properties:
hibernate:
dialect: org.hibernate.dialect.MariaDBDialect
format_sql: true
id:
new_generator_mappings: false
build.gradle
plugins {
id 'org.springframework.boot' version '2.3.9.RELEASE'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'org.asciidoctor.convert' version '1.5.8'
id 'java'
id 'groovy'
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.h2database:h2'
annotationProcessor 'org.projectlombok:lombok'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage',module: 'junit-vintage-engine'
}
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'
testCompile 'org.spockframework:spock-core:1.3-groovy-2.5'
testCompile 'org.spockframework:spock-spring:1.3-groovy-2.5'
compile 'org.apache.commons:commons-lang3:3.11'
compile 'org.javassist:javassist:3.24.0-GA'
runtime 'MysqL:mysql-connector-java'
runtime 'org.mariadb.jdbc:mariadb-java-client:2.7.1'
compile 'junit:junit:4.12'
implementation 'org.mapstruct:mapstruct:1.3.1.Final'
implementation group: 'com.google.guava',name: 'guava',version: '23.0'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.3.1.Final'
testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.3.1.Final'
}
解决方法
我想知道如果我只是将键名 mysql_password
更改为 mysql_pass
与此更改有关的问题:
spring.datasource.password=${mysql_pass:ravi@123}