micronaut-core icon indicating copy to clipboard operation
micronaut-core copied to clipboard

Support default methods as default value source for @ConfigurationProperties interfaces

Open Ksnz opened this issue 3 years ago • 3 comments

Feature description

I have a property class like

@Getter
@Setter
@Introspected
@ConfigurationProperties("some-path")
public class SomeProperties {
...
private Path tempPath = Path.of(FileUtils.getTempDirectoryPath()).resolve(SUBDIRECTORY);
...
}

with lombok annotations to reduce boilerplate and property tempPath with calculated default value. I want to refactor it to an interface type, to reduce boilerplate without using lombok

@ConfigurationProperties("some-path")
public interface SomeProperties {
...
Path getTempPath()
...
}

but now i can't build a default value cause @Bindable(defaultValue = ) allows only constants. I had expected that default methods can solve it

default Path getTempPath() {
    return Path.of(FileUtils.getTempDirectoryPath()).resolve(SUBDIRECTORY);
}

but it wouldn't. It would be nice to implement a feature to allow use default interface method as default property source. :pleading_face:

Ksnz avatar May 23 '22 07:05 Ksnz

I ran into this one as well. I agree it would be a nice feature to have.

kevind-wgu avatar Nov 30 '22 21:11 kevind-wgu

I take that back. It was actually working just fine for me. I was just misinterpreting what I was seeing.

kevind-wgu avatar Nov 30 '22 22:11 kevind-wgu

Can you please confirm that this is still an issue in the latest version of Micronaut?

ojebari-ma avatar May 25 '25 23:05 ojebari-ma