JBoss Fuse OSGi envers 不工作

JBoss Fuse OSGi envers not working

我想使用 hibernate envers 审计来生成音频 tables 并将其部署到 Jboss fuse OSGi Karaf 容器。 在我的 pom 文件中的实体 class 和 hibernate-envers jar 中添加了 @Audited 符号。

这是我的 pom.xml 文件,

<parent>
    <groupId>fuse-examples</groupId>
    <artifactId>fuse-spring-hibernate-module</artifactId>
    <version>1.0-SNAPSHOT</version>
</parent>


<artifactId>fuse-blueprint-hibernate</artifactId>
<packaging>bundle</packaging>

<name>Business Service</name>

<properties>
    <camel-version>1.5.0</camel-version>
    <maven-bundle-plugin>2.4.0</maven-bundle-plugin>
    <javax.persistence>2.0.0</javax.persistence>
</properties>

<dependencies>
    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>javax.persistence</artifactId>
        <version>${javax.persistence}</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
    </dependency>
    <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-envers</artifactId>
     </dependency>
    <dependency>
        <groupId>org.apache.geronimo.specs</groupId>
        <artifactId>geronimo-jpa_2.0_spec</artifactId>
        <version>1.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.geronimo.specs</groupId>
        <artifactId>geronimo-jta_1.1_spec</artifactId>
        <version>1.1.1</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.5</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

<build>
    <defaultGoal>install</defaultGoal>
    <plugins>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <version>2.4.0</version>
            <extensions>true</extensions>
            <configuration>
                <instructions>
                    <Bundle-SymbolicName>business-service</Bundle-SymbolicName>
                    <Meta-Persistence>META-INF/persistence.xml</Meta-Persistence>
                    <Import-Package>
                        org.hibernate.envers,
                        javax.sql,
                        javax.persistence,
                        org.hibernate.proxy,
                        javassist.util.proxy,
                        org.slf4j
                    </Import-Package>
                    <Include-Resource>src/main/resources</Include-Resource>
                </instructions>
            </configuration>
        </plugin>
    </plugins>
</build>

如果我从 pom.xml 中删除 org.hibernate.envers,则会创建 table,但不会生成 _aud table。 我错过了什么设置? osgi 容器或 pom.xml 中是否遗漏了任何设置? 或者任何想要在蓝图中设置的东西 xml?

帮帮我。

经过一些研究JBoss Fuse Karaf based OSGi container,我完成了任务。 实际上,我们构建用于将其部署到 OSGi 容器的包,我们应该设置一些设置。首先我们要知道OSGi容器加载的包是什么,嵌入到bundle中的包是什么。 捆绑清单文件将对此进行定义。这是每个包的根设置。 在硬核框架中,依赖项可以嵌入到包中。 我的错误是我刚刚宣布 org.hibernate.envers 使用 hibernate envers。

                 <Import-Package>
                    org.hibernate.envers,
                    javax.sql,
                    javax.persistence,
                    org.hibernate.proxy,
                    javassist.util.proxy,
                    org.slf4j
                </Import-Package>

大多数时候 class加载问题可能会发生,如果发生这种情况,资源可能会空。 解决方案是我们应该导入所有的东西。

这里我粘贴了我的清单文件,它工作正常。

Manifest-Version: 1.0
Bnd-LastModified: 1481971039345
Build-Jdk: 1.8.0_112
Built-By: Smile
Bundle-Activator: com.fuse.hibernate.services.OsgiBundleActiva
 tor
Bundle-Blueprint: OSGI-INF/blueprint/blueprint.xml
Bundle-ClassPath: .,hibernate-envers-4.2.22.Final-redhat-1.jar
Bundle-ManifestVersion: 2
Bundle-Name: FUSE-HIBERNATE
Bundle-SymbolicName: fuse-hibernate
Bundle-Version: 1.0.0.SNAPSHOT
Created-By: Apache Maven Bundle Plugin
Export-Package: <Exported Packages>
Export-Service: com.fuse.repository.CustomRepository
Import-Package: org.hibernate.annotations;version="[4.2,5)",org.hibernat
 e.annotations.common.reflection;version="[4.0,5)",javax.persistence;ver
 sion="[2.0,3)",org.hibernate.proxy;version="[4.2,5)",javassist.util.pro
 xy;version="[3.18,4)",org.slf4j;version="[1.7,2)",javax.management,java
 x.naming,javax.persistence.metamodel;version="[2.0,3)",javax.transactio
 n;version="[1.1,2)",org.apache.commons.beanutils;version="[1.8,2)",org.
 apache.commons.lang3;version="[3.0,4)",org.apache.tools.ant,org.dom4j,o
 rg.dom4j.io,org.dom4j.tree,org.hibernate;version="[4.2,5)",org.hibernat
 e.action.spi;version="[4.2,5)",org.hibernate.cache;version="[4.2,5)",or
 g.hibernate.cfg;version="[4.2,5)",org.hibernate.collection.spi;version=
 "[4.2,5)",org.hibernate.criterion;version="[4.2,5)",org.hibernate.diale
 ct;version="[4.2,5)",org.hibernate.engine.jdbc.spi;version="[4.2,5)",or
 g.hibernate.engine.loading.internal,org.hibernate.engine.spi;version="[
 4.2,5)",org.hibernate.engine.transaction.spi;version="[4.2,5)",org.hibe
 rnate.event.service.spi;version="[4.2,5)",org.hibernate.event.spi;versi
 on="[4.2,5)",org.hibernate.id;version="[4.2,5)",org.hibernate.id.enhanc
 ed;version="[4.2,5)",org.hibernate.integrator.spi;version="[4.2,5)",org
 .hibernate.internal,org.hibernate.internal.util;version="[4.2,5)",org.h
 ibernate.internal.util.collections,org.hibernate.internal.util.config,o
 rg.hibernate.internal.util.xml,org.hibernate.jdbc;version="[4.2,5)",org
 .hibernate.mapping;version="[4.2,5)",org.hibernate.metamodel.source;ver
 sion="[4.2,5)",org.hibernate.metamodel.spi;version="[4.2,5)",org.hibern
 ate.persister.collection;version="[4.2,5)",org.hibernate.persister.enti
 ty;version="[4.2,5)",org.hibernate.property;version="[4.2,5)",org.hiber
 nate.service;version="[4.2,5)",org.hibernate.service.classloading.spi;v
 ersion="[4.2,5)",org.hibernate.service.jdbc.dialect.internal,org.hibern
 ate.service.jndi;version="[4.2,5)",org.hibernate.service.spi;version="[
 4.2,5)",org.hibernate.sql;version="[4.2,5)",org.hibernate.tool.hbm2ddl;
 version="[4.2,5)",org.hibernate.type;version="[4.2,5)",org.hibernate.us
 ertype;version="[4.2,5)",org.jboss.logging;version="[3.1,4)",org.joda.t
 ime;version="[2.9,3)",org.osgi.framework;version="[1.6,2)",org.osgi.ser
 vice.blueprint;version="[1.0.0,2.0.0)",org.w3c.dom,javax.sql
Meta-Persistence: META-INF/persistence.xml

我们可以使用 Include-Resource 标签将 hibernate 作为资源包含进来,并确保将其添加到 bundle class 路径中。它应该可以工作。