Java Akka从源代码修改/创建配置文件
是否可以从源代码修改或创建配置文件。我正在使用远程处理创建一些客户机/服务器体系结构。我想要实现的是启动客户端应用程序的能力,例如:主机/端口,并且当没有配置文件来创建满足命令行参数的配置文件时Java Akka从源代码修改/创建配置文件,java,akka,typesafe-config,Java,Akka,Typesafe Config,是否可以从源代码修改或创建配置文件。我正在使用远程处理创建一些客户机/服务器体系结构。我想要实现的是启动客户端应用程序的能力,例如:主机/端口,并且当没有配置文件来创建满足命令行参数的配置文件时 akka { actor { provider = remote } remote { enabled-transports = ["akka.remote.netty.tcp"] netty.tcp { hostname = "127.0.0.1" &l
akka {
actor {
provider = remote
}
remote {
enabled-transports = ["akka.remote.netty.tcp"]
netty.tcp {
hostname = "127.0.0.1" <--- here
port = 2553 <--- here
}
}
}
akka{
演员{
提供者=远程
}
遥远的{
已启用的传输=[“akka.remote.netty.tcp”]
netty.tcp{
hostname=“127.0.0.1”是的,您可以在代码中修改或创建配置。以下摘录自Akka:
以编程方式修改配置的示例如下:
// make a Config with just your special setting
Config myConfig = ConfigFactory.parseString("something=somethingElse");
// load the normal config stack (system props, then application.conf, then reference.conf)
Config regularConfig = ConfigFactory.load();
// override regular stack with myConfig
Config combined = myConfig.withFallback(regularConfig);
// put the result in between the overrides (system props) and defaults again
Config complete = ConfigFactory.load(combined);
// create ActorSystem
ActorSystem system = ActorSystem.create("myname", complete);
以编程方式创建配置的示例(这是在Scala中,但您可以将其改编为Java):
import akka.actor.ActorSystem
import com.typesafe.config.ConfigFactory
val customConf = ConfigFactory.parseString("""
akka.actor.deployment {
/my-service {
router = round-robin-pool
nr-of-instances = 3
}
}
""")
// ConfigFactory.load sandwiches customConfig between default reference
// config and default overrides, and then resolves it.
val system = ActorSystem("MySystem", ConfigFactory.load(customConf))