Domanda

A volte è necessario estende un quadro. A volte è necessario per agganciare nel ciclo di vita di richiesta / risposta, ad esempio per un parametro vincolante o di scrivere un modulo di protezione. Come potrebbe questo essere fatto nel 1.x play framework?

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top