我无法在Spring Boot中从yaml中注入Map。
我无法在Spring Boot中从yaml中注入Map。
我在application.yaml文件中有以下数值:\nimport-charge-fields:\n 4: billDate\n 1001: validUntil\n 7: totalAmount\n 24: purpose\n
\n然后我尝试在服务中注入它:\n
@Value("${import-charge-fields}") private Mapfields;
\n但是我得到了异常:\n
\nCaused by: java.lang.IllegalArgumentException: 无法解析值\"${import-charge-fields}\"中的占位符 \'import-charge-fields\'\n
\n我尝试了以下方法:\ncharge:\n hz: 123\n fields:\n 4: billDate\n 1001: validUntil\n 7: totalAmount\n 24: purpose\n
\n以及\n
@Getter @Setter @Component @ConfigurationProperties(prefix = "charge") public class ChargeFields { private String hz; private Mapfields; }
\n以及\n
@Value("${charge.hz}") private String hz; @Value("${charge.fields}") private Mapfields;
\n但是都没有起作用。