cfg4j / cfg4j

Modern configuration library for distributed apps written in Java.

Home Page:http://cfg4j.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support default value annotations for configuration beans

remmeier opened this issue · comments

commented

It is possible to map configuration properties to configuration beans (declared as interfaces and implemented with dynamic proxies accessing the configuration sources).

It should also be possible to annotate those configuration interfaces with default values. Like:

public interface AnnotatedTestConfig {
  @DefaultValue("13")
  public int intValue();

  @DefaultNull()
  public String someNullableValue();
}

Otherwise the call will result in exceptions if no configuration value is defined.

How about using Java 8 default methods?

	public interface AnnotatedTestConfig {

		default int intValue(){
			return 13;
		}

		default String someNullableValue(){
			return null;
		}
	}

See commit: https://github.com/RG9/cfg4j-java8/commit/e73082dcbdf6675e8dcac064b509d05283a355bd

commented

sounds good to me :-) It would be good to have a new repository and resume development because here nothing happens anymore...

thanks :) It was just an idea and I don't plan to further develop it. I used my fork of cfg4j in some in-house tool and the above solution works fine, so I'm good :)