[英]Is there any way to write JSON array list in application.properties file (spring-boot)
Is there any way to write Json array list in application.properties file (spring-boot), so that I can read whole Json with minimum code?有没有办法在 application.properties 文件(spring-boot)中写入 Json 数组列表,以便我可以用最少的代码读取整个 Json?
Below is my json object.下面是我的 json 对象。
{ "userdetail": [
{
"user": "user1",
"password": "password2",
"email": "email1"
},
{
"user": "user2",
"password": "password2",
"email": "email2"
}]}
And also if I use jasypt to encode password, then what the code will be?而且如果我使用jasypt来编码密码,那么代码会是什么?
Refer to Spring Boot Docs here 在此处参考Spring Boot 文档
You can use YAML您可以使用 YAML
my:
servers:
- dev.example.com
- another.example.com
or normal configuration property arrays:或正常的配置属性数组:
my.servers[0]=dev.example.com
my.servers[1]=another.example.com
Than you can load these properties into application this way:您可以通过以下方式将这些属性加载到应用程序中:
@ConfigurationProperties(prefix="my")
public class Config {
private List<String> servers = new ArrayList<String>();
public List<String> getServers() {
return this.servers;
}
}
For your case I would try something like:对于您的情况,我会尝试以下操作:
users.userdetail[0].user=..
users.userdetail[0].password=..
...
And read it via并通过阅读
@ConfigurationProperties(prefix="users")
public class Userdetail {
private class User {
public String user;
public String password;
public String email;
}
private List<User> userdetails = new ArrayList<User>();
public List<User> getUserdetails() {
return this.userdetails;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.