1

小さなプロジェクトに Spring Boot 1.4.2 を使用しています。私の構成クラスは以下の通りです

@Component
@PropertySource("classpath:global1.yml")
@ConfigurationProperties
public class GlobalProperties {
    private String name;

    private List<Menu> menus = new ArrayList<>();

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<Menu> getMenus() {
        return menus;
    }

    public void setMenus(List<Menu> menus) {
        this.menus = menus;
    }

    @Override
    public String toString() {
        return "GlobalProperties{" +
                ", name='" + name + '\'' +
                ", menus=" + menus + '\'' +
                '}';
    }
}

global1.yml

name: "helloworld"
menus:
    - title: Home
      name: Home
      path: /
    - title: Login
      name: Login
      path: /login

menusYAML ファイルにリストを追加しなければ、コードは問題ありませんでした。しかし、上記のファイルで、私は

Property: target.menus
Value: 
Reason: Failed to convert property value of type 'java.lang.String' to required type 'java.util.List' for property 'menus'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'com.test.Menu' for property 'menus[0]': no matching editors or conversion strategy found

さらに、これらすべてのプロパティをapplication.yml. すべて正常に動作します。説明して、これを修正するのを手伝ってください。

4

1 に答える 1