Tag: typesafe config

Akka从源代码修改/创建配置文件

是否可以从源代码修改或创建配置文件。 我正在创建一些带有远程处理的客户端/服务器架构。 我想要实现的是能够启动客户端应用程序,例如:主机/端口,当没有配置文件时,创建一个满足命令行args的配置文件。 akka { actor { provider = remote } remote { enabled-transports = [“akka.remote.netty.tcp”] netty.tcp { hostname = “127.0.0.1” <— here port = 2553 <— here } } } 配置并不是很复杂。 我想从源端口改变端口(最终主机,现在它无论如何都是localhost用于测试),因为它有点自动化,所以我可以通过将它们传递给main函数来运行多个客户端。

由Typesafe配置支持的Spring环境

我想在我的项目中使用typesafe配置(HOCON配置文件),这有助于简化和组织应用程序配置。 目前我正在使用普通的Java属性文件(application.properties),这在大项目中很难处理。 我的项目是Spring MVC(不是Spring启动项目)。 有没有办法支持我的Spring环境(我将注入到我的服务中)以支持typesafe配置。 这不应该像@Value注释,@ @Autowired Environment等那样制止我现有的环境使用。 如何以最小的努力和我的代码更改来完成此操作。 这是我目前的解决方案:寻找还有其他更好的方法 @Configuration public class PropertyLoader{ private static Logger logger = LoggerFactory.getLogger(PropertyLoader.class); @Bean @Autowired public static PropertySourcesPlaceholderConfigurer properties(Environment env) { PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer(); Config conf = ConfigFactory.load(); conf.resolve(); TypesafePropertySource propertySource = new TypesafePropertySource(“hoconSource”, conf); ConfigurableEnvironment environment = (StandardEnvironment)env; MutablePropertySources propertySources = environment.getPropertySources(); propertySources.addLast(propertySource); pspc.setPropertySources(propertySources); return […]