您需要设置 属性前缀 ,不需要 @Configuration 和 @Component, 并使用嵌入式 公共静态类 包装货币的属性
@PropertySource("classpath:config.properties") @ConfigurationProperties(prefix = "market") @Validated public class MarketConfig { List<MarketCurrency> currs; //getters setters public static class MarketCurrency { String name; String symbol; ....//getters setters
将MarketConfig.class添加到@EnableConfigurationProperties
@SpringBootApplication @EnableSwagger2 @EnableConfigurationProperties({MarketConfig.class}) public class MarketApplication implements CommandLineRunner { private final MarketService service; private final MarketConfig config; public MarketApplication(MarketService service, MarketConfig config) { this.service = service; this.config = config; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)