我在使用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();
}
是的你是對的,需要!現在我的問題是我不能將hibernate集成到我的框架中。你知道也許有辦法嗎? 我使用春分容器(Bridge.war)將這項技術集成到Tomcat中。 我認爲hibernate有很多依賴關係,我無法手動安裝它們。 –
whiteyCS
如果問題僅在依賴關係中,那麼嵌入依賴關係可能會解決它。檢查這篇文章作爲示例:http://stackoverflow.com/questions/7438167/trying-to-build-an-osgi-bundle-in-maven-with-embedded-dependencies-cant-seem-t –