0
votes

i have a jar file which has below class to load some properties -

@ConfigurationProperties(prefix = "common-list")
@Configuration
@Component
public class CommonConfig{
...
}

In my spring boot project, above class/jar is a dependency.
How do i specify where to look for this property "common-list" to load in my project?
OR
Do i need to modify the class/jar, with PropertySource annotation specifying the property file where to look for these common-list values?

I have bootstrap.properties with following line-

spring.application.name=xyz

xyz.yaml on the config server

common-list:
...

and by looking at env properties of my spring boot application, i can see the file is picked up and loaded. But CommonConfig instance doesnt get initialized with those files values.

Values are organized correctly as i have tested them by building a spring boot test application in same project where jar is created (all the values populate in CommonConfig instances correctly).

UPDATED (SOLVED)
Issue was with converting my object to json string incorrectly, which caused the advice to go in default route instead of picking correct values.

2

2 Answers

1
votes

When component scanning picks up this CommonConfig class, the ConfigurationProperties annotation will basically inject properties found in application.yml or application.properties that begin with the prefix common-list. and set them.

See a DZONE article here.

0
votes

i updated the above post with resolution.
Issue was not with loading configuration properties rather code.