@PropertySource for different yaml files in Micronaut

122 Views Asked by At

I'm working on Micronaut 4.1.3 and I can't use @PropertySource in getting the value of yaml file aside from application.yml / .properties.

@PropertySource("classpath:new.yaml")
public class TestConfig {

  private String first;
}

I encounter the issue: Incompatible types. Found: 'java.lang.String', required: 'io.micronaut.context.annotation.Property[]'

Is there a workaround on this? TIA

1

There are 1 best solutions below

0
Michal Říčan On

@PropertySource is meant to define only array of properties not the source file.

So you can do, something like

@PropertySource(
        @Property(name = "first", value = "1")
)

If you need to add the source file, you can do that by defining environments on @MicronautTest or propertySources. Where environments will be loading dedicated application-{env}.yml file.

@MicronautTest(
        environments = {"foo", "bar"},
        propertySources = {"classpath:new.yaml"}
)