road-network-renovation:
problem:
"[demo]": stop_time
"[测试]": queue
ProblemVo:
- name: demo
index: rate
space: 流向
- name: 测试
index: queue
space: 进口
这是配置文件,problen是注入map(problem的key要加[]不然的话编译会报类型转换错误),ProblemVo是注入bean的,-代表数组的元素
@Configuration
@ConfigurationProperties(prefix = "road-network-renovation")
@Component
@PropertySource(value = {"classpath:/application.yml"}, encoding = "utf-8")
@Data
public class ProblemConfig {
private Map<String, String> problem;
private List<ProblemVo> ProblemVo;
}
需要写一个配置类,属性名称要和配置的名称相同。
@Autowired
ProblemConfig problemConfig;
在service层这样去调用。
文章讲述了在处理road-network-renovation项目时遇到的配置问题,具体涉及到配置文件中的stop_time和queue参数。ProblemVo是一个bean,用于注入配置信息,数组元素表示通过-name和-index定义的不同问题。配置类ProblemConfig包含problemMap和ProblemVoList属性。在服务层,使用@Autowired注解来注入ProblemConfig。该问题涉及到类型转换错误,解决方法是正确处理配置文件中的键值对。
1173

被折叠的 条评论
为什么被折叠?



