OSGi Spring 数据 JPA 不工作

OSGi Spring Data JPA not working

我想在我的 osgi karaf 中使用 Spring 数据 bundle.So 我需要将 jpa 存储库注册为 osgi 服务并将其用于另一个包。

这是我的配置,

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:jpa="http://www.springframework.org/schema/data/jpa"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:osgi="http://www.springframework.org/schema/osgi"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.1.xsd
        http://www.springframework.org/schema/data/jpa
        http://www.springframework.org/schema/data/jpa/spring-jpa-1.2.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
        http://www.springframework.org/schema/osgi
        http://www.springframework.org/schema/osgi/spring-osgi-1.2.xsd">


    <context:annotation-config/>


    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <constructor-arg ref="entityManagerFactory"/>
    </bean>

    <osgi:reference id="entityManagerFactory" interface="javax.persistence.EntityManagerFactory"/>

    <tx:annotation-driven/>

    <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"/>

    <jpa:repositories base-package="org.redhat.support.repository"/>

      <osgi:service interface="org.redhat.support.repository.TestingRepository" ref="testingRepository"/>

</beans>

保险丝异常消息是,

12:05:07,920 | ERROR | xtenderThread-19 | ContextLoaderListener            | 210 - org.springframework.osgi.extender - 1.2.1 | Application context refresh failed (OsgiBundleXmlApplicationContext(bundle=business-service, config=osgibundle:/META-INF/spring/*.xml))
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/data/jpa]
Offending resource: URL [bundle://500.0:0/META-INF/spring/spring.xml]

    at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)[203:org.apache.servicemix.bundles.spring-beans:3.2.16.RELEASE_1]
    at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)[203:org.apache.servicemix.bundles.spring-beans:3.2.16.RELEASE_1]
    at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:80)[203:org.apache.servicemix.bundles.spring-beans:3.2.16.RELEASE_1]
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.error(BeanDefinitionParserDelegate.java:315)[203:org.apache.servicemix.bundles.spring-beans:3.2.16.RELEASE_1]
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1429)[203:org.apache.servicemix.bundles.spring-beans:3.2.16.RELEASE_1]
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1422)[203:org.apache.servicemix.bundles.spring-beans:3.2.16.RELEASE_1]
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:187)[203:org.apache.servicemix.bundles.spring-beans:3.2.16.RELEASE_1]
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:147)[203:org.apache.servicemix.bundles.spring-beans:3.2.16.RELEASE_1]
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:101)[203:org.apache.servicemix.bundles.spring-beans:3.2.16.RELEASE_1]
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:495)[203:org.apache.servicemix.bundles.spring-beans:3.2.16.RELEASE_1]
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:391)[203:org.apache.servicemix.bundles.spring-beans:3.2.16.RELEASE_1]

如何解决这个问题?有什么建议么。 提前致谢。

此错误告诉您没有安装提供 spring 数据 jpa 名称空间的包。您是否安装了 spring 数据包?

即使您正确安装了所有内容,我也不确定 spring 数据在 OSGi 中是否有效。 Spring 很久以前就放弃了 OSGi。所以我会尽量避免在 OSGi 中使用任何 spring 技术。