【发布时间】:2018-01-31 15:43:34
【问题描述】:
我有一个问题,我真的不知道如何解决它,对我来说这没有任何意义。谁能告诉我错误在哪里,因为我看不到。我正在使用spring-boot
这里有 yml 文件:
spring:
profiles: dev
devices:
list:
- id : TV1
type : TV
value : boolean
name : TV_sufragerie
- id : TV2
type : TV
value : boolean
name : TV_dormitor
- id : Therme1
type : Therme
value : Double
name : Therme-hol
- id : SmartBulb1
type : SmartBulb
value : SmartBulbValue
name : SmartBulbDormitor
这就是我尝试从 yml 文件中获取数据的方式:
@Component
@ConfigurationProperties("devices")
public class DeviceYml {
private List<DevicesList> list = new ArrayList<>();
public static class DevicesList {
private String id;
private String type ;
private List<String> value = new ArrayList<>();
private String name;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public List<String> getValue() {
return value;
}
public void setValue(List<String> value) {
this.value = value;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "YAMLConfigDevice [id=" + id + ", type=" + type + ", value=" + value + ", name=" + name + "]";
}
}
public List<DevicesList> getDevices() {
return list;
}
public void setDevices(List<DevicesList> list) {
this.list = list;
}
@Override
public String toString() {
return "devicesList=" + list + "";
}
}
我还在 applicaton.properties 中有这个:
spring.profiles.active=dev
【问题讨论】:
-
你能正确地格式化你的 yml,它不可能读取它。 Yml 文件只有在格式正确的情况下才能工作。而且你在 yml 中没有
spring.profiles.active。你只有spring.profiles
标签: java spring spring-boot web yaml