现在,我正在做这个EJB教程:http://programming.manessinger.com/tutorials/an-eclipse-glassfish-java-ee-6-tutorial/#heading_toc_j_23,但我使用JBoss 7.0而不是GlassFish,而不是DerbyDB,我使用PostgreSQL和Hibernate作为持久性提供程序。我的问题是,我无法部署EAR并测试web服务(这是我在ATM教程中的位置),因为JBoss给了我以下错误:
ERROR [org.jboss.msc.service.fail] (MSC service thread 1-7) MSC00001: Failed to start service jboss.persistenceunit."JEETutorialEAR.ear/JEETutorialEJB.jar#JEETutorialEJB": org.jboss.msc.service.StartException in service jboss.persistenceunit."JEETutorialEAR.ear/JEETutorialEJB.jar#JEETutorialEJB": Failed to start service
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1780) [jboss-msc-1.0.1.GA.jar:1.0.1.GA]
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_27]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_27]
at java.lang.Thread.run(Thread.java:662) [:1.6.0_27]
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: JEETutorialEJB] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:908)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:884)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
at org.jboss.as.jpa.service.PersistenceUnitService.createContainerEntityManagerFactory(PersistenceUnitService.java:143)
at org.jboss.as.jpa.service.PersistenceUnitService.start(PersistenceUnitService.java:77)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1824) [jboss-msc-1.0.1.GA.jar:1.0.1.GA]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1759) [jboss-msc-1.0.1.GA.jar:1.0.1.GA]
... 3 more
Caused by: org.hibernate.HibernateException: Specified JDBC Driver org.postgresql.Driver class not found
at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:102)
at org.hibernate.service.internal.BasicServiceRegistryImpl.configureService(BasicServiceRegistryImpl.java:80)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:145)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:118)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:208)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:85)
at org.hibernate.service.internal.BasicServiceRegistryImpl.configureService(BasicServiceRegistryImpl.java:80)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:145)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:118)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:70)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2253)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2249)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1720)
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:76)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:899)
... 9 more
Caused by: java.lang.ClassNotFoundException: org.postgresql.Driver from [Module "org.hibernate:main" from local module loader @624b035d (roots: C:\Users\myname\jboss-as-web-7.0.2.Final\modules)]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:191) [jboss-modules.jar:1.0.2.GA]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:361) [jboss-modules.jar:1.0.2.GA]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:333) [jboss-modules.jar:1.0.2.GA]
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:310) [jboss-modules.jar:1.0.2.GA]
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:103) [jboss-modules.jar:1.0.2.GA]
at java.lang.Class.forName0(Native Method) [:1.6.0_27]
at java.lang.Class.forName(Class.java:169) [:1.6.0_27]
at org.hibernate.internal.util.ReflectHelper.classForName(ReflectHelper.java:191)
at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:99)
... 23 more
我的persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="JEETutorialEJB" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/jeetutorial"/>
<property name="hibernate.connection.user" value="postgres"/>
<property name="hibernate.connection.password" value="postgres"/>
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
<property name="hibernate.default_schema" value="public"/>
<property name="hibernate.default_catalog" value="jeetutorial"/>
<property name="hibernate.connection.username" value="postgres"/>
</properties>
</persistence-unit>
</persistence>
我在项目路径中添加了PostgreSQL JDBC驱动程序。我做了,这里建议的是:http://jan.zawodny.pl/blog/2011/07/jboss-7-postgresql-9没有数据源配置(我想这是由Eclipse在启动服务器期间完成的。)
答案 0 :(得分:1)
您需要手动部署驱动程序,例如在独立模式下将其复制到 $ JBOSS / standalone / deployments /。无需将其打包为模块。
在AS7.1的未来版本中,可以再次使用经典的-ds.xml文件来创建数据源。但这只是一个评论:)