2016-07-27 50 views
1

在读取stackoverflow上的answers对之后。我试图执行它的建议方式,但我仍然没有得到我的component中的字符串列表。将application.yml中的字符串列表加载到组件中

这里是我的application.yml文件

appName: 
    db: 
    host: localhost 
    username: userX 
    password: passX 
    driverClassName: org.postgresql.Driver 
    shipment: 
    providers: 
     supported1: 
     - one 
     - two 

而且我component类是

@Component 
@ConfigurationProperties(prefix = "appName.shipment.providers") 
public class ProviderUtil { 
    List<String> supported1; 

    /* This class has other util methods as well */ 
} 

在这里,我期待的是supported1将有串onetwo的列表中,但它是空的。有人能帮助这里发生的事情以及如何解决它吗?

回答

1

你的类路径是否具有spring-boot-configuration-processor依赖性? 尽量显得here

而且还从@Component改变你的bean @Configuration

+0

是啊,我有整整增加它它在文档中提到的方法。与'可选'值设置为'真正',我用'组件'因为这个响应>> http://stackoverflow.com/questions/26699385/spring-boot-yaml-configuration-for-a-list-of-字符串...这就是说,我已经尝试了'配置'和'组件',但没有运气 –

+0

尝试分享你的代码,看看我们能否以某种方式帮助你。 – bilak

+0

我想出了这个问题。我没有提供getters/setters。我已经公开了这个领域,我认为它会起作用 –