简体   繁体   中英

No error message during Spring Boot launch for nested @ConfigurationProperties

In my spring boot application, I have a class to deal with application.properties files

@Validated
@ConfigurationProperties(prefix = "cassandre.trading.bot.exchange")
public class ExchangeParameters

This class has properties like this:

/** Exchange name. For example : coinbase, kraken, kucoin. */
@NotEmpty(message = "Exchange name required, for example : coinbase, kraken, kucoin...")
private String name;

/** API username. */
@NotEmpty(message = "API username required")
private String username;

If spring boot don't find them, I have correct error messages like :

Property: cassandre.trading.bot.exchange.secret
Value: null
Reason: API secret required

Property: cassandre.trading.bot.exchange.name
Value: null
Reason: Exchange name required, for example : coinbase, kraken, kucoin...

But in my class, I also have nested properties:

/** Modes. */
@Valid
private static Modes modes = new Modes();

/** API Calls rates. */
@Valid
private static Rates rates = new Rates();

/** Exchange API rate calls. */
@ConfigurationProperties(prefix = "cassandre.trading.bot.exchange.modes")
public static class Modes {

        /** Set it to true to use the sandbox. */
        @NotNull(message = "Sandbox parameter required, set it to true to use the sandbox")
        private Boolean sandbox;

        /** Set it to true to use the dry mode. */
        @NotNull(message = "Dry parameter required, set it to true to use the dry mode")
        private Boolean dry;

If rates are missing, I have correct messages for the rates.

But I set no parameters at all, i have error messages for all fields except for nested properties like rates.

Any idea ? thanks a lot

I found the solution. Don't use static field and class

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM