gpt4 book ai didi

hibernate - Tomcat + OSGi + Hibernate + maven ClassNotFoundException org.hibernate.ServiceRegistry

转载 作者:行者123 更新时间:2023-11-28 23:37:15 25 4
gpt4 key购买 nike

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

现在我想访问一个数据库并使用一个包获取数据。我已经通过 JPA 注释映射了我的类,我想使用 Hql 查询来获取数据。对于我想使用 hibernate 的数据访问,我在 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();
}

最佳答案

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

关于hibernate - Tomcat + OSGi + Hibernate + maven ClassNotFoundException org.hibernate.ServiceRegistry,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23504036/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com