相关疑难解决方法(0)

如何在Scala Play Framework中对服务器启动执行操作?

我的目录中有一个配置文件servers.conf,conf/只要路由/servers被命中,我的ServerController就会读取该配置文件.这不具备性能,因为当文件不会更改时,它需要在每次连续命中时重新读取配置文件.此外,如果配置文件有问题,我可以尽快告诉用户,而不是在页面命中时抛出异常.

目前我在我的这个ServerController.scala:

case class Server(ip: String, port: String)

/**
  * This controller creates an `Action` to handle HTTP requests to the
  * application's server page.
  */
@Singleton
class ServerController @Inject() extends Controller {

  /**
    * Create an Action to render an HTML page with a the list of servers.
    * The configuration in the `routes` file means that this method
    * will be called when the application receives a `GET` request with …
Run Code Online (Sandbox Code Playgroud)

scala startup playframework playframework-2.5

18
推荐指数
1
解决办法
6161
查看次数

GlobalSettings onStart仅在第一次请求后才会触发

当我启动播放服务器时,我只需要运行一些代码.使用GlobalSettings.OnStart()时,我注意到代码仅在对服务器的第一个(http)请求之后执行.任何想法如何在服务器启动之后和发送任何请求之前运行我的代码?

谢谢

onstart playframework playframework-2.1

4
推荐指数
1
解决办法
763
查看次数