tjtjtjのメモ

自分のためのメモです

play1.2系の自作プラグイン

PlayFrameworkといえばトレンドはplay2.0なのでしょうが、うちはまだplay1.2系です。play1.2系で自作プラグインを作ってみました。

plugins.MyPlugin 作成

  • play.PlayPluginをextends
  • onなんたらをOverride
  • パッケージは適当に
package plugins;

import play.PlayPlugin;

public class MyPlugin extends PlayPlugin
{
    public void onLoad() 
    {
        play.Logger.info("@@@ MyPlugin.onLoad");
    }

    public void onApplicationReady() 
    {
        play.Logger.info("@@@ MyPlugin.onApplicationReady");
    }

    public void onApplicationStart() 
    {
        play.Logger.info("@@@ MyPlugin.onApplicationStart");
    }

    public void enhance(ApplicationClass applicationClass) throws Exception 
    {
        play.Logger.info("@@@ MyPlugin.enhance : %s", applicationClass.name);
    }

}

conf/play.plugins 作成

  • プライオリティ:プラグインクラス
  • プライオリティはデフォルトのものを参考にしつつ決める

こんな感じに。

100001:plugins.MyPlugin

デフォルトプラグインのプライオリティはここ参照

動作確認

アプリケーションを起動するとこうなり、play.Logger.infoできていることがわかります。

>play test
~        _            _
~  _ __ | | __ _ _  _| |
~ | '_ \| |/ _' | || |_|
~ |  __/|_|\____|\__ (_)
~ |_|            |__/
~
~ play! 1.2.5, http://www.playframework.org
~ framework ID is test
~
~ Running in test mode
~ Ctrl+C to stop
~
INFO  ~ Starting
INFO  ~ @@@ MyPlugin.onLoad
WARN  ~ You're running Play! in DEV mode
~
~ Go to http://localhost:9000/@tests to run the tests
~
INFO  ~ @@@ MyPlugin.onApplicationReady
INFO  ~ Listening for HTTP on port 9000 (Waiting a first request to start) ...
INFO  ~ @@@ MyPlugin.onLoad
INFO  ~ Connected to jdbc:mysql://localhost/plugintest?useUnicode=yes&characterEncoding=UTF-8&connectionCollation=utf8_general_ci
INFO  ~ @@@ MyPlugin.onApplicationStart
INFO  ~ Application 'plugintest' is now started !