Spring load yaml config not read all values

I am trying to configure and use YAML as a configuration file in my Spring Boot 1.5.1 project.

My YAML file is as follows:

hue:
    user: cdKjsOQIRY8hqweAasdmx-WMsn
    ip: "http://192.168.1.69"
    scenes:
        sunstatus:
            enabled: true
            id: 93yv8JekmAneCU9
            group: 1
        disable:
            enabled: true
            id: 93yv8JekmAneCU9
            group: 6

It works great to read hue.getUser (). However, hue.getScenes () for some reason returns null. My Java code for Hue Config is as follows:

@Configuration
@ConfigurationProperties(prefix = "hue")
public class Hue {
    private String user;
    private String ip;
    private Scenes scenes;

    /*
     * Getters and setters of course
     */

    public class Scenes {
        private Sunstatus sunstatus;
        private Disable disable;

        /*
         * Getters and setters
         */

        public class Sunstatus {
            private boolean enabled;
            private String id;
            private String group;

            /*
             * Getters and setters
             */
        }

        public class Disable {
            private boolean enabled;
            private String id;
            private String group;

            /*
             * Getters and setters
             */
        }
    }
}

I also tried to annotate each class with a prefix, both in the format hue.scenes.sunstatus, scenes.sunstatus, and just sunstatus.

In addition, I also tried using the @Value annotation for a bit of luck.

These are the same results if I save the data in application.yml or in an external file. Only getUser () can always reach.

What am I doing wrong here?

+1
2

, - , @NestedConfigurationProperty

public class Scenes {

    @NestedConfigurationProperty
    private Sunstatus sunstatus;

    @NestedConfigurationProperty
    private Disable disable;

@NestedConfigurationProperty , , ( ) , .

, ( ) public static.

0

.

@Configuration
@ConfigurationProperties(prefix = "hue")
public class Hue {
    private String user;
    private String ip;
    private Scenes scenes = new Scenes();

    /*
     * Getters and setters of course
     */

    public class Scenes {
        private Sunstatus sunstatus = new Sunstatus();
        private Disable disable = new Disable();

        /*
         * Getters and setters
         */

        public class Sunstatus {
            private boolean enabled;
            private String id;
            private String group;

            /*
             * Getters and setters
             */
        }

        public class Disable {
            private boolean enabled;
            private String id;
            private String group;

            /*
             * Getters and setters
             */
        }
    }
}
0

Source: https://habr.com/ru/post/1676940/


All Articles