Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@ConfigurationProperties referencing properties that themselves reference other properties

Tags:

spring-boot

project.name=my-project
base.url=http://localhost:8080
cas.url=http://my-server:8010/cas
cas.callback.url=${base.url}/${project.name}

Basically I want to use the above in a spring-boot ConfigurationProperties but the casCallbackUrl is always null.

@Component
@ConfigurationProperties(prefix = "cas")
@Getter
@Setter
public class CasSettings {

    @NotBlank
    private String url; //this is resolved correctly

    @NotBlank
    private String callbackUrl; //callbackUrl is null

}

update

Well I got it working by camelCasing the property names, but according to the documentation you should be able to use dot notation for property names.

from:

cas.callback.url=${base.url}/${project.name}

to:

cas.callbackUrl=${base.url}/${project.name}

Why is spring-boot not picking up the dot notation?

like image 929
jax Avatar asked Mar 17 '15 23:03

jax


People also ask

What is the preferred approach to externalizing configuration and why?

My preferred approach is to externalise all configuration so that the artefact taken from the build server is environment agnostic and can be deployed onto any environment .

What is the difference between @configuration and @component?

3. How They Differ. The main difference between these annotations is that @ComponentScan scans for Spring components while @EnableAutoConfiguration is used for auto-configuring beans present in the classpath in Spring Boot applications. Now, let's go through them in more detail.

How do you externalize a constants from a Spring configuration file into a properties file?

You can use properties files, YAML files, environment variables and command-line arguments to externalize configuration. Property values can be injected directly into your beans using the @Value annotation, accessed via Spring's Environment abstraction or bound to structured objects.

Does spring boot follow configuration over convention?

Spring has always favoured convention over configuration, which means it takes up the majority of working uses cases into consideration and goes by it rather than nit-picking an exact configuration and dependencies required for a specific application development.


1 Answers

The dot represents a separate object within the configuration properties object. cas.callback-url would work.

like image 144
SteveO Avatar answered Oct 09 '22 10:10

SteveO