我完成了本教程中编写的所有步骤,但是当我在 Jboss 上部署应用程序时,出现了这些错误
17:31:05,744 INFO [org.jboss.as.server.deployment](MSC 服务线程 1-7)JBAS015876:开始部署“JPAEJBProject.jar” 17:31:05,754 INFO [org.jboss.as.jpa] (MSC 服务线程 1-7)JBAS011401:读取 JPADB 的 persistence.xml 17:31:05,764 INFO [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor](MSC 服务线程 1-7)会话 bean 的 JNDI 绑定在部署单元部署“JPAEJBProject.jar”中命名为 ProjectBean 如下:
java:global/JPAEJBProject/ProjectBean!com.ibytecode.business.IProject java:app/JPAEJBProject/ProjectBean!com.ibytecode.business.IProject java:module/ProjectBean!com.ibytecode.business.IProject java:jboss/exported/JPAEJBProject /ProjectBean!com.ibytecode.business.IProject java:global/JPAEJBProject/ProjectBean java:app/JPAEJBProject/ProjectBean java:module/ProjectBean
17:31:06,076 INFO [org.jboss.as.server](DeploymentScanner-threads - 2)JBAS015870:部署“JPAEJBProject.jar”的部署已回滚并显示失败消息 {“JBAS014771:缺少/不可用依赖项的服务”= > ["jboss.persistenceunit.\"JPAEJBProject.jar#JPADB\"jboss.naming.context.java.MySQLDSMissing[jboss.persistenceunit.\"JPAEJBProject.jar#JPADB\"jboss.naming.context.java.MySQLDS]" ]}
这是我的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="JPADB">
<jta-data-source>java:/MySQLDS</jta-data-source>
<properties>
<property name="showSql" value="true"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
</properties>
</persistence-unit>
</persistence>
我在 zmodules\com\mysql\main 中创建了一个 module.xml,内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="com.mysql">
<resources>
<resource-root path="mysql-connector-java-5.1.25-bin.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
</dependencies>
</module>
我还在 zmodules\com\mysql\main 中粘贴了“mysql-connector-java-5.1.25-bin”并修改了“stanalone.xml”以添加数据源和驱动程序,如图所示:
<subsystem xmlns="urn:jboss:domain:datasources:1.0">
<datasources>
<datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
<connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url>
<driver>h2</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
</datasource>
<datasource jndi-name="java:/MySQLDS"
pool-name="MySQLDS" jta="true" enabled="true" use-java-context="true">
<connection-url>jdbc:mysql://localhost:3306/ejbexample</connection-url>
<driver>mysqlDriver</driver>
<security>
<user-name>root</user-name>
<password>root</password>
</security>
</datasource>
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
<driver name="mysqlDriver" module="com.mysql">
<xa-datasource-class>com.mysql.jdbc.Driver</xa-datasource-class>
</driver>
</drivers>
</datasources>
</subsystem>
有人能帮我吗?