2014-05-06 56 views
0

我在使用Bridge.WAR的Apache Tomcat服务器(7.0.52)中嵌入了OSGi框架。我可以使用它并在其上运行捆绑包。 我的包是使用maven构建的。Tomcat + OSGi + Hibernate + maven ClassNotFoundException org.hibernate.ServiceRegistry

现在我想访问数据库并使用一个包获取数据。我已经通过JPA批注映射了我的类,并且我想使用Hql查询来获取数据。对于数据访问,我想使用休眠,我把它放在POM文件的依赖中。 我建立了mvn clean install并嵌入到OSGi容器中,我试着启动它,但是它没有打包org.hibernate包的类。

我不知道该如何处理它。任何人都可以帮忙吗?我完全失去了...

我的pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.database</groupId> 
    <artifactId>RecipePrDatabase</artifactId> 
    <version>1.0</version> 
    <packaging>bundle</packaging> 
    <build> 
     <sourceDirectory>src</sourceDirectory> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.felix</groupId> 
       <artifactId>maven-bundle-plugin</artifactId> 
       <version>2.4.0</version> 
       <extensions>true</extensions> 
       <configuration> 
        <source>1.7</source> 
        <target>1.7</target> 
        <instructions> 
         <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName> 
         <Bundle-Name>${pom.artifactId}</Bundle-Name> 
         <Bundle-Version>${pom.version}</Bundle-Version> 
         <Bundle-Activator>com.database.service.impl.Activator</Bundle-Activator> 
         <Import-Package> 
          org.osgi.framework;version="1.3.0", 
         </Import-Package> 
        </instructions> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
    <dependencies> 
     <dependency> 
      <groupId>org.apache.felix</groupId> 
      <artifactId>org.osgi.core</artifactId> 
      <version>1.4.0</version> 
     </dependency> 
     <dependency> 
      <groupId>org.hibernate</groupId> 
      <artifactId>hibernate-core</artifactId> 
      <version>4.3.5.Final</version> 
     </dependency> 
     <dependency> 
      <groupId>org.hibernate</groupId> 
      <artifactId>hibernate-osgi</artifactId> 
      <version>4.3.5.Final</version> 
     </dependency> 
     <dependency> 
      <groupId>mysql</groupId> 
      <artifactId>mysql-connector-java</artifactId> 
      <version>5.1.27</version> 
     </dependency> 
     <dependency> 
      <groupId>javax.servlet</groupId> 
      <artifactId>servlet-api</artifactId> 
      <version>3.0-alpha-1</version> 
     </dependency> 
     <dependency> 
      <groupId>taglibs</groupId> 
      <artifactId>standard</artifactId> 
      <version>1.1.2</version> 
     </dependency> 
     <dependency> 
      <groupId>jstl</groupId> 
      <artifactId>jstl</artifactId> 
      <version>1.2</version> 
     </dependency> 
     <dependency> 
      <groupId>org.hibernate</groupId> 
      <artifactId>hibernate</artifactId> 
      <version>3.0alpha</version> 
     </dependency> 
     <dependency> 
      <groupId>org.hibernate</groupId> 
      <artifactId>hibernate-annotations</artifactId> 
      <version>3.5.6-Final</version> 
     </dependency> 
     <dependency> 
      <groupId>antlr</groupId> 
      <artifactId>antlr</artifactId> 
      <version>2.7.7</version> 
     </dependency> 
     <dependency> 
      <groupId>dom4j</groupId> 
      <artifactId>dom4j</artifactId> 
      <version>1.6.1</version> 
     </dependency> 
     <dependency> 
      <groupId>org.hibernate.common</groupId> 
      <artifactId>hibernate-commons-annotations</artifactId> 
      <version>4.0.4.Final</version> 
     </dependency> 
     <dependency> 
      <groupId>org.hibernate.javax.persistence</groupId> 
      <artifactId>hibernate-jpa-2.0-api</artifactId> 
      <version>1.0.0.Final</version> 
     </dependency> 
     <dependency> 
      <groupId>org.javassist</groupId> 
      <artifactId>javassist</artifactId> 
      <version>3.18.1-GA</version> 
     </dependency> 

     <dependency> 
      <groupId>org.jboss.logging</groupId> 
      <artifactId>jboss-logging</artifactId> 
      <version>3.1.3.GA</version> 
     </dependency> 
     <dependency> 
      <groupId>org.jboss.logging</groupId> 
      <artifactId>jboss-logging-annotations</artifactId> 
      <version>1.2.0.Beta1</version> 
     </dependency> 
     <dependency> 
      <groupId>org.jboss.spec.javax.transaction</groupId> 
      <artifactId>jboss-transaction-api_1.2_spec</artifactId> 
      <version>1.0.0.Final</version> 
     </dependency> 
     <dependency> 
      <groupId>org.jboss</groupId> 
      <artifactId>jandex</artifactId> 
      <version>1.1.0.Final</version> 
     </dependency> 


     <dependency> 
      <groupId>org.slf4j</groupId> 
      <artifactId>slf4j-api</artifactId> 
      <version>1.7.7</version> 
     </dependency> 
      <dependency> 
        <groupId>org.jboss.spec.javax.interceptor</groupId> 
        <artifactId>jboss-interceptors-api_1.2_spec</artifactId> 
        <version>1.0.0.Final</version> 
       </dependency> 
      <dependency> 
        <groupId>javax.enterprise</groupId> 
        <artifactId>cdi-api</artifactId> 
        <version>1.1</version> 
       </dependency> 
    </dependencies> 

</project> 

,我用这个连接:

public void setUp() throws Exception { 
     Configuration conf = new Configuration().configure("hibernate.cfg.xml"); 
     sr = new StandardServiceRegistryBuilder().applySettings(
       conf.getProperties()).build(); 
     sessionFactory = conf.buildSessionFactory(sr); 
    } 

    public void initDB() throws Exception { 

     session = sessionFactory.openSession(); 
    } 

    public void closeDB() { 
     if (session.isOpen()) 
      session.close(); 
    } 

回答

0

你用什么方式嵌入你的罐子?有没有关于错过org.hibernate的日志信息?我想你的OSGI容器对于hibernate包没有任何线索。
您的<Import-Package>部分仅包含org.osgi.framework,但是如果您的包使用了org.hibernate,则还需要指定org.hibernate(有关<Import-Package>的更多详细信息:http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html)。

+0

是的你是对的,需要!现在我的问题是我不能将hibernate集成到我的框架中。你知道也许有办法吗? 我使用春分容器(Bridge.war)将这项技术集成到Tomcat中。 我认为hibernate有很多依赖关系,我无法手动安装它们。 – whiteyCS

+0

如果问题仅在依赖关系中,那么嵌入依赖关系可能会解决它。检查这篇文章作为示例:http://stackoverflow.com/questions/7438167/trying-to-build-an-osgi-bundle-in-maven-with-embedded-dependencies-cant-seem-t –

相关问题