当前位置:网站首页>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
边栏推荐
- Leetcode 198: 打家劫舍
- 7.2 brush two questions
- Advanced API (character stream & net for beginners)
- LeetCode
- Map interface and method
- Gridome + strapi + vercel + PM2 deployment case of [static site (3)]
- Basic knowledge about SQL database
- [set theory] Stirling subset number (Stirling subset number concept | ball model | Stirling subset number recurrence formula | binary relationship refinement relationship of division)
- 3311. Longest arithmetic
- 为什么说数据服务化是下一代数据中台的方向?
猜你喜欢
Leetcode 198: 打家劫舍
你开发数据API最快多长时间?我1分钟就足够了
IPv4 address
Summary of abnormal mechanism of interview
Common problems in io streams
TreeMap
Interfaces and related concepts
[set theory] equivalence classes (concept of equivalence classes | examples of equivalence classes | properties of equivalence classes | quotient sets | examples of quotient sets)*
专题 | 同步 异步
[set theory] partition (partition | partition example | partition and equivalence relationship)
随机推荐
SecureCRT password to cancel session recording
Basic components and intermediate components
Introduction of transformation flow
[set theory] Stirling subset number (Stirling subset number concept | ball model | Stirling subset number recurrence formula | binary relationship refinement relationship of division)
你开发数据API最快多长时间?我1分钟就足够了
[set theory] partition (partition | partition example | partition and equivalence relationship)
Docker builds MySQL: the specified path of version 5.7 cannot be mounted.
New stills of Lord of the rings: the ring of strength: the caster of the ring of strength appears
Advanced API (character stream & net for beginners)
带你全流程,全方位的了解属于测试的软件事故
PAT甲级真题1166
GStreamer ffmpeg avdec decoded data flow analysis
4everland: the Web3 Developer Center on IPFs has deployed more than 30000 dapps!
Use of file class
【无标题】
2021-07-18
URL programming
C代码生产YUV420 planar格式文件
1. E-commerce tool cefsharp autojs MySQL Alibaba cloud react C RPA automated script, open source log
Various postures of CS without online line