当前位置:网站首页>Read config configuration file of vertx
Read config configuration file of vertx
2022-07-03 07:25:00 【Sleeping Empire】
Introduce
Vertx Handle configuration file reading , vertx-config-yaml File load read
1. maven Project dependence
<dependencies>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-web</artifactId>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-config-yaml</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.lance.common</groupId>
<artifactId>vertx-common-core</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
2.YAML File configuration
user:
name: Jim
age: 20
birth: 2012-10-21
sex: 1
server:
port: 8000
3. Start loading profile , And into the config In the middle
public class ConfigApplication {
public static void main(String[] args) {
Vertx vertx = Vertx.vertx();
ConfigRetriever retriever = readYaml(vertx);
retriever.getConfig(json -> {
DeploymentOptions options = new DeploymentOptions().setConfig(json.result());
vertx.deployVerticle(MainApp.class.getName(), options);
});
}
private static ConfigRetriever readYaml(Vertx vertx) {
ConfigStoreOptions store = new ConfigStoreOptions()
.setType("file")
.setFormat("yaml")
.setOptional(true)
.setConfig(new JsonObject().put("path", "application.yaml"));
return ConfigRetriever.create(vertx, new ConfigRetrieverOptions().addStore(store));
}
}
4. Configuration file read and use
@Slf4j
public class MainApp extends AbstractVerticle {
@Override
public void start(Promise<Void> startPromise) throws Exception {
HttpServer server = vertx.createHttpServer();
server.requestHandler(new MainRoute().create(vertx));
ConfigProperties properties = config().mapTo(ConfigProperties.class);
int port = properties.getServer().getPort();
log.info("===>json: {}, port: {}", properties, port);
server.listen(port, http -> {
if (http.succeeded()) {
startPromise.complete();
log.info("HTTP server started on port {}", port);
} else {
startPromise.fail(http.cause());
}
});
}
}
// Get current context Next config file
JsonObject jsonObject = Vertx.currentContext().config();
ConfigProperties properties = jsonObject.mapTo(ConfigProperties.class);
5. Full address of the project
边栏推荐
猜你喜欢

Deep learning parameter initialization (I) Xavier initialization with code

Common architectures of IO streams
![[solved] sqlexception: invalid value for getint() - 'Tian Peng‘](/img/bf/f6310304d58d964b3d09a9d011ddb5.png)
[solved] sqlexception: invalid value for getint() - 'Tian Peng‘

Dora (discover offer request recognition) process of obtaining IP address

Store WordPress media content on 4everland to complete decentralized storage

Leetcode 213: 打家劫舍 II

Common problems in io streams
![[Fiddler problem] solve the problem about Fiddler's packet capturing. After the mobile network is configured with an agent, it cannot access the Internet](/img/9d/42dfef67246740f0dba0c6d8f1b625.jpg)
[Fiddler problem] solve the problem about Fiddler's packet capturing. After the mobile network is configured with an agent, it cannot access the Internet

IP home online query platform

《指环王:力量之戒》新剧照 力量之戒铸造者亮相
随机推荐
深度学习参数初始化(一)Xavier初始化 含代码
[most detailed] latest and complete redis interview book (50)
File operation serialization recursive copy
3311. Longest arithmetic
Selenium key knowledge explanation
GStreamer ffmpeg avdec decoded data flow analysis
Sorting, dichotomy
2. E-commerce tool cefsharp autojs MySQL Alibaba cloud react C RPA automated script, open source log
Chrome 98 Private Network Access problem w/ disabled web security: Request had no target IP address
691. 立方体IV
Strategy mode
Common APIs
twenty million two hundred and twenty thousand three hundred and nineteen
LeetCode
【开发笔记】基于机智云4G转接板GC211的设备上云APP控制
Homology policy / cross domain and cross domain solutions /web security attacks CSRF and XSS
Lombok -- simplify code
Advanced APL (realize group chat room)
4279. Cartesian tree
SecureCRT取消Session记录的密码