如何扩展游戏框架? [英] How to extend the playframework?

查看:104
本文介绍了如何扩展游戏框架?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时候,有必要扩展框架.有时有必要进入请求/响应生命周期,例如进行参数绑定或编写安全模块. 在playframework 1.x中怎么做到?

Sometime it's necessary to extends a framework. Sometimes it's necessary to hook into the request/response lifecycle, for example for a parameter binding or to write a security module. How could this be done in the playframework 1.x?

推荐答案

有两种方法可以扩展播放1.x.首先,您可以编写自己的模块. 此处进行了详细说明.如果您要提供iText之类的库或提供特殊的身份验证机制,这将非常有用.

There are two ways to extend play 1.x. First you can write your own module. This is described in detail here. This is useful if you want provide a library such as iText or provide a special authentication mechanism.

第二种方法是编写一个PlayPlugin.这通常是在模块中完成的,但这不是必要条件.编写PlayPlugin需要两个步骤:

The second way is to write a PlayPlugin. This is often done in modules but it's not a necessary condition. To write a PlayPlugin requires two steps:

  1. 编写一个扩展类PlayPlugin并覆盖其方法,例如称为myPackage.MyPlugin.
  2. 注册您的插件.这是通过创建一个名为play.plugins的文件并将其放入类路径来完成的.该文件必须包含1003:myPackage.MyPlugin之类的行.
  1. Write a class which extends the class PlayPlugin and override some of its methods, for example called myPackage.MyPlugin.
  2. Register your plugin. This is done by creating a file named play.plugins and putting it into the classpath. The file must contain a line like 1003:myPackage.MyPlugin.

数字定义插件的调用顺序.我建议使用ids>1000.如果要在框架插件之前加载它,请查看此处(该ID自1.1.1开始有效.)

The number defines the order in which the plugins are called. I recommend to use ids > 1000. If you want it to load before a framework plugin, look here (The ids are valid since 1.1.1).

就是这样.要了解如何使用插件,请参见 javadoc .您可以插入:

That's it. To get a feeling of what you can do with a Plugin see the javadoc. You can hook into:

  • 请求/响应周期
  • 绑定过程
  • 应用程序启动/停止
  • classloading

不幸的是,javadoc文档很少,但是请不要犹豫地查看playframework本身的代码.这很容易理解,并为您提供了好主意.

Unfortunately the javadoc documentation is minimal, but don't hesitate to look into the code of the playframework itself. It's easy to understand and gives you good ideas.

这篇关于如何扩展游戏框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆