首页 技术 正文
技术 2022年11月10日
0 收藏 446 点赞 3,558 浏览 914 个字

前言

不可避免的要用dropwizard作为service框架。持续学习。上次在dropwizard中使用feign,使用hystrix, 算是基本入门了。接下来就是基于此的优化。

把需要使用Configuration的逻辑从Application里分离出来

在开始的demo中,由于不知道dropwizard怎么传播类,怎么注入, 把所有的初始化的东西都放到Application里去new出来。现在发现有办法可以分离部分配置逻辑。

现在把feign的基础配置抽离出来:

public class ConnectivityBundle implements ConfiguredBundle<HelloWorldConfiguration> {
@Override
public void run(HelloWorldConfiguration configuration, Environment environment) throws Exception {
//init hystrix config
Map<String, Object> hystrixConfig = configuration.getHystrixConfig();
for (final Map.Entry<String, Object> config : hystrixConfig.entrySet()) {
ConfigurationManager.getConfigInstance().setProperty(config.getKey(), config.getValue());
System.out.println(config.getKey());
}
} @Override
public void initialize(Bootstrap<?> bootstrap) { }
}

然后,在Application中添加就好了。

com.test.HelloWorldApplication

@Override
public void initialize(Bootstrap<HelloWorldConfiguration> bootstrap) {
bootstrap.addBundle(new ConnectivityBundle());
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,488
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,903
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,737
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,489
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,128
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,290