本帖最后由 ing 于 2019-7-15 09:08 编辑
我想的结果应该是只有"User"被输出
实际输出结果 Roles:[USER, ADMIN]
这是因为什么?
第2张图的完整代码
[Asm] 纯文本查看 复制代码 @Component
@ConfigurationProperties(prefix = "acme")
public class AcmeProperties {
private boolean enabled;
private String remoteAddress;
private final Security security = new Security();
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public String getRemoteAddress() {
return remoteAddress;
}
public void setRemoteAddress(String remoteAddress) {
this.remoteAddress = remoteAddress;
}
public Security getSecurity() {
return security;
}
public static class Security{
private String username;
private String password;
private List<String> roles = new ArrayList<>(Collections.singleton("USER"));
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public List<String> getRoles() {
return roles;
}
public void setRoles(List<String> roles) {
this.roles = roles;
}
}
}
参考https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config-typesafe-configuration-properties |