DEV Community

Discussion on: Spring @Value annotation tricks

Collapse
 
turekbot profile image
TurekBot • Edited

Very useful, thanks!

Can I create an instance of a Path object from the properties file using SpEL?

Thanks for any help you can offer!

Collapse
 
habeebcycle profile image
Habeeb Okunade

Yes, through construtor injection.
For instance,

private final Path filePath;
public PathConfig(@Value("${name-to-your-path}") String pathStr) {
this.filePath = Paths.get(pathStr).toAbsolutePath().normalize();
}