I need to load a property from a .yml file, which contains the path to a folder where the application can read files from.
I\'m using the following code
In yml properties file :
xxxx:
page:
rowSize: 1000
Create your Yaml properties config class :
@Configuration
@EnableConfigurationProperties
@ConfigurationProperties(prefix = "xxxx")
public class YmlPropertiesConfig {
private Page page;
public Page getPage() {
return page;
}
public void setPage(Page page) {
this.page = page;
}
public class Page {
private Integer rowSize;
public Integer getRowSize() {
return rowSize;
}
public void setRowSize(Integer rowSize) {
this.rowSize = rowSize;
}
}
}
Finally get it and use it :
public class XXXXController {
@Autowired
private YmlPropertiesConfig ymlProperties;
public String getIt(){
Integer pageRowSize = ymlProperties.getPage().getRowSize();
}
}