0

私のアプリケーションでは、注釈を使用して、アプリケーションの「onStart」フック中に実行したいいくつかのメソッドをマークしています。私のコードは次のようなものです:

@Override
public void onStart(Application app) {
    Reflections reflections = new Reflections("", new SubTypesScanner(false), new MethodAnnotationsScanner(), app.classloader()); //also tried without classloader
    Set<Method> onStartMethods = reflections.getMethodsAnnotatedWith(OnStart.class); //OnStart is my annotation

    if (CollectionUtils.isNotEmpty(onStartMethods)) {
        for (Method osm : onStartMethods) {
            // execute the methods
        }
    } else {
        // I CRASH the server because this is not a behaviour I want
    }

}

一点、これは両方使っplay runても問題なく動くのですが、使っplay startたら動かなくなりましplay distた。このエラーは、テスト サーバー (EC2 ubuntu 13.10) と私の開発マシン (Ubuntu 14.04LTS) の両方で発生します。

これを使用して、自分のマシンでテストします。

$alias testdeploy
alias testdeploy='play compile && play dist && unzip -o target/universal/*.zip -d ~/test-deploy/ && bash ~/test-deploy/server_crm-1.0/bin/server_crm'

PlayでJava7を使用しています! 2.2. 私はいくつかの洞察を必要としています。何が起こっているのですか...そして何よりも、どうすればこれを修正できますか?

更新:もちろん私もテストしplay stageました...と同じ結果dist

4

1 に答える 1

1

"" でリフレクションを開始すると、ClasspathHelper.forPackage("") から取得した URL が効果的にスキャンされます。

おそらく、さまざまな展開環境でこれらの URL を実行時に調べて、"" の代わりに正しいパラメーターを使用することをお勧めします。

それ以外の場合は、別の ClasspathHelper.forXXX を使用して正しい URL を取得してください。

于 2014-04-29T09:16:38.263 に答える