【问题标题】:How to read properties file in Play framework 2.5如何在 Play 框架 2.5 中读取属性文件
【发布时间】:2017-07-20 20:18:36
【问题描述】:
我正在使用 Play 框架制作网站。
但是当我尝试读取属性文件时遇到问题。
我搜索并尝试使用[Play.application().resourceAsStream("test.properties")],但出现错误[Play.application().resourceAsStream("test.properties")]。
但有错误:
[Play类型中的方法aplication(Aplication)不适用
对于参数()]
我该怎么办?
【问题讨论】:
标签:
java
scala
playframework-2.5
【解决方案1】:
需要注入Configuration对象:
斯卡拉
class HomeController @Inject()(conf: Configuration) extends Controller{
def post() = Action{
val testProp = conf.getString("test.properties")
...
Java
public class HomeController extends Controller{
@Inject
private Configuration configuration;
public Result post(){
final String testProp = configuration.getString("test.properties")
...