Akka之配置文件加载
来源:互联网 发布:linux vim 复制命令 编辑:程序博客网 时间:2024/06/07 04:58
akka启动时,默认加载application.conf配置文件,所以有关辅助的配置可以在该文件中定义。
此外,akka也提供可以在代码中以硬编码的方式,加入或覆盖配置。如:
// Override the configuration of the port Config config = ConfigFactory.parseString( "akka.remote.netty.tcp.port=" + port) .withFallback(ConfigFactory.parseString("akka.actor.provider = akka.cluster.ClusterActorRefProvider")) .withFallback(ConfigFactory.parseString("akka.cluster.seed-nodes = [\"akka.tcp://ClusterSystem@10.42.197.163:2551\"]")) .withFallback( ConfigFactory.load()); // Create an Akka system ActorSystem system = ActorSystem.create("ClusterSystem", config);
如在application.conf中定义:
TestApp {connection {db { mysql { url = "jdbc:mysql://localhost:3306/" dbname = "sampleDB" driver = "com.mysql.jdbc.Driver" username = "root" userpassword = "password" } }}}
ActorSystem _system = ActorSystem.create("Extension-Test");Config config = _system.settings().config();
则得到的配置如上所示,获取配置,通过:
ActorSystem _system = ActorSystem.create("Extension-Test");Config config = _system.settings().config();String url = config.getConfig("TestApp").getString("connection.db.mysql.url");String url2 = config.getString("TestApp.connection.db.mysql.url");
如果使用指定TestApp加载配置如:
ActorSystem _system = ActorSystem.create("Extension-Test",ConfigFactory.load().getConfig("TestApp"));Config config = _system.settings().config();
通过调用发现,其自动将TestApp过滤掉了,其只作为加入配置的key值,除此以外无其它作用。
实际开发中,少用硬编码,所以第一种采用第一种方式,于配置文件中可以直接去掉TestApp,直接以connection开头
阅读全文
0 0
- Akka之配置文件加载
- java之配置文件加载
- Spring之配置文件加载方式
- Spring之配置文件加载方式
- Spring之配置文件加载方式
- Spring之配置文件加载方式
- 加载配置文件之路径问题
- Spring之配置文件加载方式
- Scala消息通信之akka,akka案例
- 初识Akka之Router
- akka学习之untypedpersistentactor
- Scala之AKKA
- Akka之Hello World
- 学习akka之helloword
- 学习akka之future
- 学习akka之Router
- 学习akka之dispatcher
- 学习akka之邮箱
- 2017年12月19日的工作总结
- java read write text
- 第八章-压缩文件
- electron打包
- 222
- Akka之配置文件加载
- 数据挖掘学习------------------2-关联规则-3-FP_Growth算法
- Kea DHCP配置介绍和基本使用
- jetty 6.x https访问双向认证配置方法
- iOS系统及微信中audio自动播放
- 设计模式-模板方法模式
- java自学网站资源List
- lesson 11:. 使用UDP协议编写一个网络程序,设置接收端程序的监听端口是8001,发送端发送的数据是“Hello, world”。
- 阿里云下linux系统mysql无法远程访问