我知道我可以从properties文件行属性创建对象。我想要一个动态的对象数组,就像这样。
application.properties
heroes.hero1=1,superman,kent
heroes.hero2=2,batman,wayne假设某个时候有人会在档案中添加另一个英雄。春天有可能自动理解英雄阵列的添加吗?有解决办法吗?还是从txt文件中读取和构造这样的对象更容易。
发布于 2017-12-11 12:58:32
实际上,您可以使用Spring功能来实现这个功能:
例如,创建一个新的Java类(现在为Getters/ Setters使用Lombok )
@ConfigurationProperties(prefix = "heroes")
@Getter
@Setter
public class HeroesProperties {
private Map<String, List<String>> heroesMapping;
}在您的application.properties中,您可以以您的方式动态地添加更多的英雄。
例如。
heroes.hero1=1,superman,kentheroes.hero2=2,xx,aaheroes.hero3=3,yy,bbheroes.heroN=4,zz,cchttps://stackoverflow.com/questions/47753064
复制相似问题