我有一个使用Thymeleaf构建的Web应用程序,我想将其与SqlServer DB连接;我创建了persistence.xml并被识别,但是在服务器启动期间,我有下一个跟踪:
13:35:01,355 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 50) MSC000001: Failed to start service jboss.persistenceunit."vp301b-ear.ear/vp301b.war#unidadPersistencia": org.jboss.msc.service.StartException in service jboss.persistenceunit."vp301b-ear.ear/vp301b.war#unidadPersistencia": javax.persistence.PersistenceException: Cannot find scanner class. hibernate.ejb.resource_scanner=org.jboss.as.jpa.hibernate4.HibernateAnnotationScanner
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:103) [jboss-as-jpa-7.5.0.Final-redhat-21.jar:7.5.0.Final-redhat-21]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.7.0_80]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_80]
at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_80]
at org.jboss.threads.JBossThread.run(JBossThread.java:122) [jboss-threads-2.1.2.Final-redhat-1.jar:2.1.2.Final-redhat-1]
Caused by: javax.persistence.PersistenceException: Cannot find scanner class. hibernate.ejb.resource_scanner=org.jboss.as.jpa.hibernate4.HibernateAnnotationScanner
at org.hibernate.ejb.Ejb3Configuration.buildScanner(Ejb3Configuration.java:406)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:593)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:75)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:200) [jboss-as-jpa-7.5.0.Final-redhat-21.jar:7.5.0.Final-redhat-21]
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.access$600(PersistenceUnitServiceImpl.java:57) [jboss-as-jpa-7.5.0.Final-redhat-21.jar:7.5.0.Final-redhat-21]
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:99) [jboss-as-jpa-7.5.0.Final-redhat-21.jar:7.5.0.Final-redhat-21]
... 4 more
Caused by: java.lang.ClassNotFoundException: org.jboss.as.jpa.hibernate4.HibernateAnnotationScanner from [Module "deployment.vp301b-ear.ear.vp301b.war:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:213) [jboss-modules.jar:1.3.6.Final-redhat-1]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:459) [jboss-modules.jar:1.3.6.Final-redhat-1]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:408) [jboss-modules.jar:1.3.6.Final-redhat-1]
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:389) [jboss-modules.jar:1.3.6.Final-redhat-1]
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:134) [jboss-modules.jar:1.3.6.Final-redhat-1]
at java.lang.Class.forName0(Native Method) [rt.jar:1.7.0_80]
at java.lang.Class.forName(Unknown Source) [rt.jar:1.7.0_80]
at org.hibernate.internal.util.ReflectHelper.classForName(ReflectHelper.java:170)
at org.hibernate.ejb.Ejb3Configuration.buildScanner(Ejb3Configuration.java:403)
... 9 more
我试图更改休眠版本,修改persistence.xml,删除并在jboss目录中手动添加休眠jar,搜索此错误...但无济于事。
我的persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<persistence-unit name="unidadPersistencia">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>my entity</class>
<properties>
<property name="hibernate.ejb.cfgfile" value="hibernate.cfg.xml" />
<property name="javax.persistence.jdbc.driver" value="MY DRIVER"/>
<property name="javax.persistence.jdbc.url" value="DATABASE"/>
<property name="javax.persistence.jdbc.user" value="USER"/>
<property name="javax.persistence.jdbc.password" value="PWD"/>
</properties>
</persistence-unit>
</persistence>
对pom.xml的休眠和持久性依赖关系:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0</version>
</dependency>
问题更新:
在添加由mm6表示的依赖关系之后,跟踪已更改,新的跟踪如下:
15:07:14,589 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 50) MSC000001: Failed to start service jboss.persistenceunit."vp301b-ear.ear/vp301b.war#unidadPersistencia": org.jboss.msc.service.StartException in service jboss.persistenceunit."vp301b-ear.ear/vp301b.war#unidadPersistencia": java.lang.NoClassDefFoundError: org/hibernate/internal/util/ClassLoaderHelper
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:103)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.7.0_80]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_80]
at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_80]
at org.jboss.threads.JBossThread.run(JBossThread.java:122) [jboss-threads-2.1.2.Final-redhat-1.jar:2.1.2.Final-redhat-1]
Caused by: java.lang.NoClassDefFoundError: org/hibernate/internal/util/ClassLoaderHelper
at org.hibernate.ejb.Ejb3Configuration.<init>(Ejb3Configuration.java:175)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:74)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:200)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.access$600(PersistenceUnitServiceImpl.java:57)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:99)
... 4 more
Caused by: java.lang.ClassNotFoundException: org.hibernate.internal.util.ClassLoaderHelper from [Module "deployment.vp301b-ear.ear.vp301b.war:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:213) [jboss-modules.jar:1.3.6.Final-redhat-1]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:459) [jboss-modules.jar:1.3.6.Final-redhat-1]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:408) [jboss-modules.jar:1.3.6.Final-redhat-1]
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:389) [jboss-modules.jar:1.3.6.Final-redhat-1]
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:134) [jboss-modules.jar:1.3.6.Final-redhat-1]
... 9 more
答案 0 :(得分:0)
异常看起来像是它希望您使用AnnotationConfiguration,并且缺少依赖项,这些依赖项仍被jboss包含,并且不使用jar中的内容。尝试以下依赖项:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.6.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.transaction</groupId>
<artifactId>jboss-transaction-api_1.1_spec</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.common</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>4.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.15.0-GA</version>
</dependency>