2

I have a Spring Boot project with two YAML files in resources folder:

  • application.yml
  • metrics.yml

metrics.yml looks like this:

metrics:
    activeMetrics:
        -   type: TYPE_A
            value: 10
        -   type: TYPE_B
            value: 5

The class for it looks like this:

@Data
@Component
@ConfigurationProperties("metrics")
public class ActiveMetrics {
    private final List<Metric> activeMetrics = new ArrayList<>();
}

Main class is annotated with:

@PropertySources({
        @PropertySource("classpath:/metrics.yml"),
        @PropertySource("classpath:/project.yml")
})

After application startup the activeMetrics list is empty, however, if I place the same config inside of application.yml the list initializes successfully.

metrics.yml is also loaded successfully, because when the path isn't right Spring Boot throws an exception.

How do I initialize this bean with second YAML file?

Leonid Bor
  • 2,064
  • 6
  • 27
  • 47
  • application.yml will over ride all this, Please try after removing application.yml OR $ java -jar myproject.jar --spring.config.location=classpath:/application,classpath:/metrics.properties – GoutamS Apr 24 '18 at 16:11
  • Is there any change after Spring Boot 2.0? I want some latest and easiest options as I think Spring Boot provides them! – Anand Varkey Philips May 05 '18 at 07:00

0 Answers0