How to extend the playframework?

*爱你&永不变心* 提交于 2019-12-17 15:25:15

问题


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:


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.

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. 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.

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).

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

  • The request/response-cycle
  • The binding process
  • application start/stop
  • classloading

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.



来源:https://stackoverflow.com/questions/4699250/how-to-extend-the-playframework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!