无法使用springboot通过java bean中的application.properties绑定属性

无法使用springboot通过java bean中的application.properties绑定属性,java,spring,spring-boot,Java,Spring,Spring Boot,我的java类如下所示 @ConfigurationProperties(prefix = "resilience.component.io") public class IO16BrickletProperties { private List<IOBricklet> bricklets = new ArrayList<IOBricklet>(); public List<IOBricklet> getBricklets() {

我的java类如下所示

@ConfigurationProperties(prefix = "resilience.component.io")
public class IO16BrickletProperties {

    private List<IOBricklet> bricklets = new ArrayList<IOBricklet>();

    public List<IOBricklet> getBricklets() {
        return bricklets;
    }

    public void setBricklets(List<IOBricklet> bricklets) {
        this.bricklets = bricklets;
    }
}
我得到的错误是

2018-03-20 16:17:35.103  WARN 1344 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'IO16BrickletProperties': Could not bind properties to 'IO16BrickletProperties': prefix=resilience.component.io, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'resilience.component.io.bricklets[0].configuration' to java.util.List<netc.resilience.model.IOBricklet$Configuration>
2018-03-20 16:17:35.212  WARN 1344 --- [  restartedMain] o.s.b.f.support.DisposableBeanAdapter    : Invocation of destroy method 'close' failed on bean with name 'eurekaRegistration': org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration': Singleton bean creation not allowed while singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)

有人能找出我为什么会犯这个错误吗。我引用了spring的版本,但无法解决此错误。在属性文件中配置的正确方法是什么。

需要将内部类设置为静态。参考

因此,更新代码如下所示

public class IOBricklet extends Bricklet {

    private List<Configuration> configuration = new ArrayList<Configuration>();

    public List<Configuration> getConfiguration() {
        return configuration;
    }

    public void setConfiguration(List<Configuration> configuration) {
        this.configuration = configuration;
    }

    static class Configuration {
        private char port;
        private char pin;
        private String serviceName;

        getters and setters...
        toString()...
    }
}
2018-03-20 16:17:35.103  WARN 1344 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'IO16BrickletProperties': Could not bind properties to 'IO16BrickletProperties': prefix=resilience.component.io, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'resilience.component.io.bricklets[0].configuration' to java.util.List<netc.resilience.model.IOBricklet$Configuration>
2018-03-20 16:17:35.212  WARN 1344 --- [  restartedMain] o.s.b.f.support.DisposableBeanAdapter    : Invocation of destroy method 'close' failed on bean with name 'eurekaRegistration': org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration': Singleton bean creation not allowed while singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)
public class IOBricklet extends Bricklet {

    private List<Configuration> configuration = new ArrayList<Configuration>();

    public List<Configuration> getConfiguration() {
        return configuration;
    }

    public void setConfiguration(List<Configuration> configuration) {
        this.configuration = configuration;
    }

    static class Configuration {
        private char port;
        private char pin;
        private String serviceName;

        getters and setters...
        toString()...
    }
}