私はVirgo-Tomcat-Serverを実行しています。そのキーをマップからOSGi:他のバンドルのClassloaderを取得する方法
bundle.a.MyEnum
コンテキスト
bundle.b
を介して受信し、SpelExpressionParserを使って春の式言語され、サンプルの表現は、「取得(T(bundle.aだろうEnumMapがあり、 .MyEnum).SAMPLEKEY) "パーサー(それぞれのTypeLocator)は、bundle.aのClassLoaderにアクセスする必要があります。
だから私はやった:
TypeLocator typeLocator = new StandardTypeLocator(getBundleAClassLoader());
StandardEvaluationContext evaluationContext = new StandardEvaluationContext();
evaluationContext.setTypeLocator(typeLocator);
spelExpressionParser = new SpelExpressionParser();
spelExpressionParser.parseExpression(expression)).getValue(evaluationContext, context);
質問はbundle.bのクラスでbundle.aのクラスローダを取得するための適切な方法は何か、ですか? は試みのカップルの後、私が見つけた唯一の作業溶液は次のとおりです。
private static ClassLoader getBundleAClassLoader() {
MyEnum bundleARef = MyEnum.SAMPLEKEY;
return bundleARef.getClass().getClassLoader();
}
編集:ソリューション
getBundleAClassLoader()
が正常に動作します
、
TypeLocator typeLocator = new StandardTypeLocator(this.getClass().getClassLoader());
必要はありません。
bundle.bの輸入bundle.a、しかしStandardEvaluationContextことなく、春クラスSpelParserExpressionはbundle.b輸入場合にClassNotFoundException – pma
もたらすbundle.bのClassLoaderを使用しますMyEnumのパッケージ、次にbundle.bのクラスローダーがクラスbundkle.a.MyEnumを見つけます –
私は修正された、それは動作します。私がthis.getClass()。getClassLoader()を試したときに、TypeLocatorが正しく設定されていなかったと思います。ありがとう! – pma