2013-04-15 12 views
14

私は現在、JPAとQueryDSLを使用するApache Karafで動作するOSGiアプリケーションを開発中です。OSGiとSpringデータを統合することは可能ですか?

現在のアプローチではなく、QueryDSLでSpringデータを使用できるかどうか疑問に思っていました。

これは、Springリポジトリが非常に便利であり、NoSQLデータベースへのアクセス用のテンプレートを将来的に役立つと感じているからです。

私はOSGiでWebコンテキストなしで通常のSpringアプリケーションを起動しようとしましたが、applicationContext.xmlまたはApplicationContext.classをロードしようとするとClassNoutFoundExceptionが発生します。

私はスプリングDMを廃止して使用したくないです。

基本的に、この統合を試みる理由はSpringリポジトリのためですが、これが必要でないと思われる場合は教えてください。これを実現する方法や、これを克服することが大丈夫かどうかに関する情報は歓迎する以上のものです。

いただきありがとうございます更新

私はorg.eclipse.gemini.blueprint.context.support.OsgiBundleXmlApplicationContextとアプリケーションコンテキストを開始することにより、スプリングを動作させることができました。 applicationContextはサービスとしてOSGiにエクスポートされ、必要なすべてのBeanを呼び出すことができます。

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0' defined in URL [bundle://251.13:0/META-INF/spring/applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.IllegalStateException: No persistence exception translators found in bean factory. Cannot perform exception translation. 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)[185:org.springframework.beans:3.1.4.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)[185:org.springframework.beans:3.1.4.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)[185:org.springframework.beans:3.1.4.RELEASE] 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)[185:org.springframework.beans:3.1.4.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)[185:org.springframework.beans:3.1.4.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)[185:org.springframework.beans:3.1.4.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1109)[187:org.springframework.context:3.1.4.RELEASE] 
    at org.eclipse.gemini.blueprint.context.support.AbstractDelegatedExecutionApplicationContext.registerBeanPostProcessors(AbstractDelegatedExecutionApplicationContext.java:502)[193:org.eclipse.gemini.blueprint.core:1.0.0.RELEASE] 
    at org.eclipse.gemini.blueprint.context.support.AbstractDelegatedExecutionApplicationContext.registerBeanPostProcessors(AbstractDelegatedExecutionApplicationContext.java:451)[193:org.eclipse.gemini.blueprint.core:1.0.0.RELEASE] 
    at org.eclipse.gemini.blueprint.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:306)[193:org.eclipse.gemini.blueprint.core:1.0.0.RELEASE] 
    at org.eclipse.gemini.blueprint.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)[193:org.eclipse.gemini.blueprint.core:1.0.0.RELEASE] 
    at org.eclipse.gemini.blueprint.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:290)[193:org.eclipse.gemini.blueprint.core:1.0.0.RELEASE] 
    at org.eclipse.gemini.blueprint.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:137)[194:org.eclipse.gemini.blueprint.extender:1.0.0.RELEASE] 
    at java.lang.Thread.run(Thread.java:662)[:1.6.0_37] 
Caused by: java.lang.IllegalStateException: No persistence exception translators found in bean factory. Cannot perform exception translation. 
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.detectPersistenceExceptionTranslators(PersistenceExceptionTranslationInterceptor.java:142)[195:org.springframework.transaction:3.1.4.RELEASE] 
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.<init>(PersistenceExceptionTranslationInterceptor.java:79)[195:org.springframework.transaction:3.1.4.RELEASE] 
    at org.springframework.dao.annotation.PersistenceExceptionTranslationAdvisor.<init>(PersistenceExceptionTranslationAdvisor.java:70)[195:org.springframework.transaction:3.1.4.RELEASE] 
    at org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor.setBeanFactory(PersistenceExceptionTranslationPostProcessor.java:103)[195:org.springframework.transaction:3.1.4.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeAwareMethods(AbstractAutowireCapableBeanFactory.java:1475)[185:org.springframework.beans:3.1.4.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1443)[185:org.springframework.beans:3.1.4.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)[185:org.springframework.beans:3.1.4.RELEASE] 

私はOpenJPAのを使用しているJPAプロバイダとして:

私が今抱えている問題は、私は<jpa:repositories base-package="x.y.z" />を宣言するとき、私は次の例外を取得していることです。 entityManagerFactoryは、青写真を使用して取得できるサービスです。私は<jpa:repositories base-package="x.y.z" />でそれを参照する必要があると思うが、applicationContext.xmlは青写真ではなく春に読み込まれるので、どうすればいいですか?

私は本当に正しい方向へのヒントを感謝します。 、使用 -

答えて

4

は、さてあなたは、ここでの選択肢のカップルを持っている、(あなたは春の豆を呼び出す必要がありますが、私はまだ行うことができると思うので、おそらく最も難しい)それは青写真を実行するために取得しようありがとうKaraf 3.0.0.RC1それはまた、あなたが使用することが可能であり、中止されている場合でもSpring-DMを使用することが最善のアプローチであるとはいえ、Springとより重要なSpring-DMのサポートを強化しているBlueprint Gemininをサポートしています特定のスプリング固有のパーツとスタンダードについては、残りの青写真。両方のフレームワークでサービスを使用するだけですべてが機能しますので、スプリングとブループリント記述子を1つのバンドルに混ぜてはいけません。

+0

春のDMが中止されていないのOSGiエンタープライズ仕様の完全なJPAの章のためのhibernate-osgi-adapterを書きました。 「Gemini Blueprint」に改名されました。 –

+0

しかし、現在はspring-dmの構文とは若干異なる青写真ですので、「中止」と呼ぶかもしれません。私はまだ特定のシナリオでそれを使用しています... :) –

+0

ありがとうAchim Nierbeck。あなたの答えのおかげで、私はSpringのDMクラスがSpringの仕事を作ったことがわかりました。私も私の答えを更新しました。 Apache KarafとSpring Dataを統合することについて何か知っていれば、本当に感謝しています。もう一度ありがとう:) – Marius

3
直接あなたのコード内で

使用Querydsl-SQLと

  • それはクラスローディング、織り、強化、キャッシングと本当に良い音が、他のトリックを使用していないとして、それはOSGiの範囲内で動作しますが混乱
  • を引き起こし
  • コードが
  • 他の人があなたのコードを理解することができるようになります「キャッシュ・強化」JPAエンジンのいずれかよりもはるかに高速に実行されます
  • あなたはSQLが実行したコマンドを正確に知っているだろう(JPA基準APIクエリを好きではありません)問題を最小限に抑えるデータベースサーバー-solving時間
  • あなたのコードは独立した任意のORMツールを使って、データベースのようになります

は、彼らがいた

  • としてのOSGiと一緒に春、春・データ、JPAおよびその他のmonoholiticの技術を使用しないでください。これらの技術をOSGiと一緒に使用することで、このようなバグを修正し、回避策を探すために多くの時間を費やすことになります。

これを主張する人々は、すでにこのような回避策を見つけるのに多くの時間を費やしました。彼らはビジネスロジックを実装することができました。彼らは今、本当にすべての概念上の問題の回避策を見つけ、次回は同じ量の作業を費やす必要はないと考えています。彼らはbidding fee auctionです。正直な人よ!どこか深く私が正しいと知っている;-)。

私は私

  • 経験でこれを言っているが(春データの誇大宣伝が始まるずっと前に)HibernateとIBMのDon't repeat the DAO記事に基づいて最適なスタックを試してみました。二回
  • は、Hibernate 4.1.xの
  • Re-implemented
+1

P .:私は賞金のためにこの答えを書かなかった。私はこれを書いて、すべてのレイヤーを統合する完全なORMベースのスタックを使用している開発者の耳にバグを残しましたが、回避策を探している時間の50%を費やしています。 –

+0

これは本当に私の質問に答えるものではありません。私はまだ深く知っていても、本当に確信していません:)あなたはおそらく正しいでしょう。しかし、これは私にあなたに賞金を授与するのに十分なほど明確です。 –