springBoot配置文件yml字符串换行问题
yaml源代码:
multiLineString1: |
line1 hello world
line2 yaml demo
line3 welcome
multiLineString2: >
line1 hello world
line2 yaml demo
line3 welcome
multiLineString3: "line1 hello world\
line2 yaml demo\
line3 welcome"
转义之后的代码:
multiLineString1: 'line1 hello world\nline2 yaml demo\nline3 welcome\n',
multiLineString2: 'line1 hello world line2 yaml demo line3 welcome\n',
multiLineString3: 'line1 hello worldline2 yaml demoline3 welcome',
Springboot 取yml文件中的数组或集合
yml配置
list:
li:
- 11
- 13
properties配置
list.li[0]=11
list.li[1]=13
yml配置集合对象还可以这样:
mail[0]:
username: xxx@xxx.com
password: axxx
mail[1]:
username: xxx@xxx.com
password: axxx
@Component
@ConfigurationProperties(prefix="list")
public class IgnoreImageIdConfig {
private List<Integer> li =new ArrayList<Integer>();
public List<Integer> getLi() {
return li;
}
public void setLi(List<Integer> li) {
this.li = li;
}
}
springboot配置数据库密码特殊字符报错问题
一般的springboot项目会有application.yml或者application.properties文件,开发中需要连接数据库时密码可能会有特殊字符,.properties文件不会报错,但是.yml文件会报错。
解决:yml中password对应的值用单引号引住('!@test')就可以了,如下
spring:
datasource:
password: '!@test'
type: com.alibaba.druid.pool.DruidDataSource
url: jdbc:mysql://localhost:3306/test?characterEncoding=utf-8
username: root