This repo illustrates how to setup a Spring boot app using yml based properties
By using this setup navigation is possible from the application.yml file to where the properties are bound in code, and back (Crtl+B, Crtl+click, etc)
Notice this dependency in pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
This is what is basically needed, then just inject that bean wherever
@Configuration
@ConfigurationProperties("my.living.rent")
class Address {
private String city;
private String country;
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
}
Also, @EnableConfigurationProperties
@SpringBootApplication
@EnableConfigurationProperties
public class NavYmlApplication {
public static void main(String[] args) {
SpringApplication.run(NavYmlApplication.class, args);
}
}
This is how it should look in the class, by clicking those green leafs the ide will take you to the location in the yml where that prop is declared
- it does not work in combination with Lombok (@Getter @Setter)
- the annotation processing must be enabled in Intellij
- I've noticed that sometimes the IDE needs some time to make the binding happen (refresh the maven config)