简体   繁体   English

如何创建 Map <string, list<string> &gt; 可以使用 Spring 的 @Value 注入的属性文件中的属性</string,>

[英]How to create a Map<String, List<String>> property in properties file that can be injectable using Spring's @Value

How do I create a Map<String, List<String>> property in properties file that can be injectable using Spring's @Value?如何在属性文件中创建可以使用 Spring 的 @Value 注入的Map<String, List<String>>属性?

Example code snippet in Properties java file属性 java 文件中的示例代码片段

@PropertySource({"file:salesforce-service.properties"})
public class Properties {
    @Value("#{${student.hobbies}}")
    private Map<String, List<String>> hobbies;
}

Here is the answer and the example code snippet in properties file:这是答案和属性文件中的示例代码片段:

student.hobbies={indoor: 'reading, drawing', outdoor: 'fishing, hiking, bushcraft'}

Reference: https://stackabuse.com/the-value-annotation-in-spring/ section --> Injecting into Maps参考: https://stackabuse.com/the-value-annotation-in-spring/部分 --> 注入 Maps

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用格式化字符串“Property:Value”制作属性映射 - how to make a map of properties using formatted string "Property:Value" 将 YAML 属性绑定到 Map <String, List<String> &gt; 使用 Spring Boot 键入 - Bind YAML properties to Map<String, List<String>> type with Spring Boot 列表中的春豆 <String> 在属性文件中 - spring bean from list<String> in a properties file Spring 引导 + Docker 撰写:如何覆盖“地图” <string, list<string> &gt;' 来自 yaml 属性的环境变量</string,> - Spring Boot + Docker Compose: How to override 'Map<String, List<String>>' environment variable from yaml properties 如何将 Excel 文件读入列表<Map<String, String> &gt; - How can I read Excel file into List<Map<String, String>> 使用流创建一个包含字符串列表的映射 - Create a Map out of a List of String(s) with streams 在 Spring XML 配置文件中使用属性字符串 - Using Properties String in Spring XML configuration file 使用XML通过字符串以外的属性来配置Spring Bean(使用属性文件) - Configure Spring Bean using XML through Property other than String (using Properties File) 如何转换 Map<string ,list> 至 Map <string , map<> &gt; 使用 Java 8</string></string> - How can I convert Map<String ,List > to Map<String , Map<>> using Java 8 Spring - 使用注释设置属性值而不使用属性文件 - Spring - Set property value using annotations without using properties file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM