groovy
repositories {
mavenCentral()
}
dependencies {
implementation 'io.activej:boot-config:$version'
}
public class AppConfig {
@Secret
private String databasePassword;
private int serverPort;
public String getDatabasePassword() {
return databasePassword;
}
public int getServerPort() {
return serverPort;
}
}
public class MyApp {
public static void main(String[] args) throws Exception {
Eventloop eventloop = Eventloop.create().withCurrentThread();
BootConfig bootConfig = ConfigModule.create()
.resolveConfig(env -> new Config()
.with("app", AppConfig.class))
.createBoot()
.If(logger.isDebugEnabled(), b -> b.withLogger(logger))
.WithEventloop(eventloop)
.run();
AppConfig appConfig = bootConfig.get("app", AppConfig.class);
logger.info("Database password: {}", appConfig.getDatabasePassword());
logger.info("Server port: {}", appConfig.getServerPort());
appConfig.setServerPort(8080);
bootConfig.commit();
}
}