Spring Boot - Detect and terminate if property not set? -


is there way spring boot web application abort @ startup if required property not set anywhere (neither in application.properties file nor other property sources)? right now, if property included in property, seem spring boot avoids substitution.

for example, in application.properties file, have line:

quartz.datasource.url=jdbc:hsqldb:${my.home}/database/my-jobstore 

right now, if "my.home" not set elsewhere, spring boot setting url literally "jdbc:hsqldb:${my.home}/database/my-jobstore" (no substitution).

i have application fail start if property my.home not set anywhere else.

create bean simple @value(${my.home}) annotated field. - spring try inject value , fail , therefore stop when value not there.


just @value(${my.home}) private string myhomevalue; enough normal (not boot) spring applications sure! not know whether boot has other configuration handle missing values: if there other failure management check value in postcreation method.

@component public static class configurationguard implements initializingbean {     @value(${my.home})    private string myhomevalue;     /**     * needed if there crude default handling missing values!!!!     *     * try first without method (and without implements initializingbean)     */    public void afterpropertiesset() {       if (this.myhomevalue == null or this.myhomevalue.equals("${my.home}") {           throw new illegalargumentexception("${my.home} must configured");       }    }  } 

Comments