1.新建yml文件,如application-test.yml
2.插入数据
3.自定义配置类
@Component//使用@Configuration也可以
@PropertySource(value = “classpath:application-test.yml”)//配置文件路径
@ConfigurationProperties(prefix = “tx2config”)
public class TX2Config {
@Value("
t
x
2
K
e
y
"
)
/
/
需
要
使
用
@
v
a
l
u
e
注
解
来
注
入
,
否
则
是
n
u
l
l
p
r
i
v
a
t
e
S
t
r
i
n
g
t
x
2
K
e
y
;
@
V
a
l
u
e
(
"
{tx2Key}")//需要使用@value注解来注入,否则是null private String tx2Key; @Value("
tx2Key")//需要使用@value注解来注入,否则是nullprivateStringtx2Key;@Value("{cameraIds}")
private String cameraIds;
public String getTx2Key() {
return tx2Key;
}
public void setTx2Key(String tx2Key) {
this.tx2Key = tx2Key;
}
public String getCameraIds() {
return cameraIds;
}
public void setCameraIds(String cameraIds) {
this.cameraIds = cameraIds;
}
}