Application global settings
来源:互联网 发布:php pdo mysql 长连接 编辑:程序博客网 时间:2024/06/05 02:44
Application global settings
The Global object
Defining a Global
object in your project allows you to handle global settings for your application. This object must be defined in the default (empty) package and must extend GlobalSettings
.
import play.api._object Global extends GlobalSettings {}
Tip: You can also specify a custom
GlobalSettings
implementation class name using theapplication.global
configuration key.
Hooking into application start and stop events
You can override the onStart
and onStop
methods to be notified of the events in the application life-cycle:
import play.api._object Global extends GlobalSettings { override def onStart(app: Application) { Logger.info("Application has started") } override def onStop(app: Application) { Logger.info("Application shutdown...") }}
Providing an application error page
When an exception occurs in your application, the onError
operation will be called. The default is to use the internal framework error page:
import play.api._import play.api.mvc._import play.api.mvc.Results._import scala.concurrent.Futureobject Global extends GlobalSettings { override def onError(request: RequestHeader, ex: Throwable) = { Future.successful(InternalServerError( views.html.errorPage(ex) )) }}
Handling missing actions and binding errors
If the framework doesn’t find an Action
for a request, the onHandlerNotFound
operation will be called:
import play.api._import play.api.mvc._import play.api.mvc.Results._import scala.concurrent.Futureobject Global extends GlobalSettings { override def onHandlerNotFound(request: RequestHeader) = { Future.successful(NotFound( views.html.notFoundPage(request.path) )) }}
The onBadRequest
operation will be called if a route was found, but it was not possible to bind the request parameters:
import play.api._import play.api.mvc._import play.api.mvc.Results._import scala.concurrent.Futureobject Global extends GlobalSettings { override def onBadRequest(request: RequestHeader, error: String) = { Future.successful(BadRequest("Bad Request: " + error)) }}
Next: Intercepting requests
- Application global settings
- Settings.Global
- R Global Option Settings
- 关于Settings.Global /Secure/System
- Financial Accounting Global Settings Configuration Steps
- Proguard error: android.provider.Settings$Global
- global.asax 中的application session
- Custom Global Application Culture & DateTime.Parse
- Settings provider system和global表格数据访问
- WinForm:应用程序设置(Application Settings)的应用
- Error "Application Blocked by Security Settings"
- Error "Application Blocked by Security Settings"
- bak 4.android use application context save global data.
- http的内置对象 Session Application Global.aspx文件
- 获取当前用户的Local Settings/Application Data文件夹
- Could not download the Silverlight application. Check web server settings
- Untie LINQ to SQL Connection String from Application Settings
- global
- HDU1238 POJ1226 Substrings 最长公共子串(子反串也算)
- LeetCode Triangle Java版本
- 2015年4月21日---开始写自己的专业博客啦
- 用数组求一位数组中的最大值,最小值和平均分,并求出有多少个数超过平均分
- win7下安装MongoDB
- Application global settings
- ICE-RFC5245摘要
- windows ffmpeg 编译 动态库 静态库 总结
- 设置ViewPager翻页滚动速度
- Spring技术详解
- eclipse +dev+django开发网站
- 趣味导学Python——画图(二)
- java接口与抽象类的对比
- UML活动图