This is in reference to this question.
Spring Boot - inject map from application.yml
In that question, they have
info:
build:
artifact: ${project.artifactId}
name: ${project.name}
description: ${project.description}
version: ${project.version}
To map this into their java code, they are suggesting to use @ConfigurationProperties
annotation. The problem with this annotation is that you have to create a New Class
and then add this annotation on top of it.
However can I directly get this onto a single field just like how @Value
annotation does?
Say I need it here like this:
// Someannotation or any other lean and clean way to get this
@Someannotation("${info}")
private Map<String, Object> map;
The above code should give me a map where key is build
and value is some Object with fields like artifact, name etc
(of course if this works, I will create a POJO for this instead of leaving it as normal Object).
Note: @ConfigurationProperties
does not work on fields which is why I am looking to see if there is a leaner and cleaner way to do this.
P.S. Also I am fine with using @ConfigurationProperties
and creating a new class, but I just wanted to see if I am missing out
on a simpler way to do this without having to create a new class altogether.