我有一个要拆分的 Play 应用:
rest - 保存休息接口的播放模块
services - 简单的 Scala 模块,包含 actor 和外部服务客户端(例如 S3)
我想创建一个 S3Client 对象类,但是在实例化它时我需要从 application.conf 中读取配置值。我不能使用play.api.Play.current.configuration因为这不是一个播放模块。
我想错了吗?实现我想要的最优雅的方式是什么?
我有一个要拆分的 Play 应用:
rest - 保存休息接口的播放模块
services - 简单的 Scala 模块,包含 actor 和外部服务客户端(例如 S3)
我想创建一个 S3Client 对象类,但是在实例化它时我需要从 application.conf 中读取配置值。我不能使用play.api.Play.current.configuration因为这不是一个播放模块。
我想错了吗?实现我想要的最优雅的方式是什么?
只需使用类型安全的配置工厂
import com.typesafe.config.ConfigFactory
val conf = ConfigFactory.load("/path/to/your/conf/file/application.conf")
//init your object with the conf file.
您甚至不需要在其中放置路径。
如果application.conf
位于根目录中,config factory
则会自动检查它是否存在。