基于Java注释注入配置属性:ADP4J
jopen
11年前
ADP4J是一个Java注释驱动的配置属性注入类库。它可以让你在项目中使用注释以声明的方式注入配置属性。
配置属性支持以下各种来源:
- System properties passed to JVM
- Properties files
- Resource bundles
- 数据库
public class Bean { @SystemProperty("threshold") private int threshold; @Property(source = "myProperties.properties", key = "bean.name") private String beanName; //getters and setters omitted }
//Instantiate your object Bean bean = new Bean(); //Instantiate ADP4J configurator Configurator configurator = new ConfiguratorBuilder().build(); //Configure your object configurator.configure(bean);