how to get my configuration values in yml - using dropwizard (microservice) Jersey D.I @Injection?(如何在 yml 中获取我的配置值 - 使用 dropwizard(微服务)Jersey D.I @Injection?)
本文介绍了如何在 yml 中获取我的配置值 - 使用 dropwizard(微服务)Jersey D.I @Injection?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码片段.
这是我的 yml 文件:
here's my yml file:
productionServer:
host: production-server.amazonaws.com
publicIp: xx.xx.xx.xx
privateIp: xx.xx.xx.xx
userName: xx.xx.xx.xx
password: xx.xx.xx.xx
remoteFilePath: fake/path/
fileName: test.txt
privateKey: private-public-key.ppk
server:
applicationConnectors:
- type: http
port: 8080
- type: https
port: 8443
keyStorePath: key.keystore
keyStorePassword: password
validateCerts: false
adminConnectors:
- type: http
port: 8081
- type: https
port: 8444
keyStorePath: key.keystore
keyStorePassword: password
validateCerts: false
MyConfiguration 类:
MyConfiguration class:
import io.dropwizard.Configuration;
public class MyConfiguration extends Configuration{
@NotNull
@JsonProperty
private ProductionServer productionServer;
// getters
public class ProdctionServer{
@NotEmpty
@JsonProperty
private host;
@NotEmpty
@JsonProperty
private publicIp;
// getters
应用类:
import io.dropwizard.Application;
public class MyApplication extends Application<MyConfiguration> {
public static void main(String[] args) throws Exception{
new MysApplication().run(args);
}
@Override
public String getName(){ return "micro-service"; }
@Override
public void initialize(Bootstrap<MyConfiguration> bootstrap){}
@Override
public void run(MyConfiguration conf, Environment environment ){
final MyResource myResource = new MyResource();
// health check
// environment.healthChecks().register("template",healthCheck);
System.out.println( "==> " + conf );
System.out.println( "==> " + conf.getProductionServer() );
// register
environment.jersey().register( MyResource );
在运行此应用程序时:
我收到如下记录:
==> MyConfiguration{server=DefaultServerFactory{applicationConnectors=[io.dropwizard.jetty.HttpConnectorFactory@623e088f, io.dropwizard.jetty.HttpsConnectorFactory@39fcbef6], adminConnectors=[io.dropwizard.jetty.HttpConnectorFactory@34f22f9d, io.dropwizard.jetty.HttpsConnectorFactory@77d67cf3], adminMaxThreads=64, adminMinThreads=1, applicationContextPath=/, adminContextPath=
沃梦达教程
本文标题为:如何在 yml 中获取我的配置值 - 使用 dropwizard(微服务)Jersey D.I @Injection?


猜你喜欢
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01