最近在做项目的时候遇到两个问题,第一个是在application.yml文件中出现配置项数据解析ConstructorException异常问题,第二个是application.yml文件中出现配置项数据“丢0”。
application.yml特殊字符处理
异常信息如下:
org.yaml.snakeyaml.constructor.ConstructorException
配置项如下:
datasource:
# 主库数据源
master:
driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowMultiQueries=true
username: root
password: mysql@127
解决方法:将带@特殊字符的配置项数据都加了双引号,如上所示password: “mysql@127”
application.yml丢0
配置项如下:
cert:
version: 1.0.0
encoding: UTF-8
signMethod: 01
代码中获取到signMethod的值为1,应该读取到01才对,修改方式同样添加双引号。
正确配置为:
cert:
version: 1.0.0
encoding: UTF-8
signMethod: "01"