![](/img/trans.png)
[英]Environment Variables in spring-boot application.properties error
[英]Is there any way to write JSON array list in application.properties file (spring-boot)
有沒有辦法在 application.properties 文件(spring-boot)中寫入 Json 數組列表,以便我可以用最少的代碼讀取整個 Json?
下面是我的 json 對象。
{ "userdetail": [
{
"user": "user1",
"password": "password2",
"email": "email1"
},
{
"user": "user2",
"password": "password2",
"email": "email2"
}]}
而且如果我使用jasypt來編碼密碼,那么代碼會是什么?
您可以使用 YAML
my:
servers:
- dev.example.com
- another.example.com
或正常的配置屬性數組:
my.servers[0]=dev.example.com
my.servers[1]=another.example.com
您可以通過以下方式將這些屬性加載到應用程序中:
@ConfigurationProperties(prefix="my")
public class Config {
private List<String> servers = new ArrayList<String>();
public List<String> getServers() {
return this.servers;
}
}
對於您的情況,我會嘗試以下操作:
users.userdetail[0].user=..
users.userdetail[0].password=..
...
並通過閱讀
@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.