@Stateless @Remote public class UserManagerBean implements UserManager {
private EntityManager entityManager;
@PersistenceContext public EntityManager getEntityManager() { return entityManager; }
public void setEntityManager(EntityManager entityManager) { this.entityManager = entityManager; }
public void add(Teacher tea) { entityManager.persist(tea); }
}
persistence.xml文件中配置: <persistence-unit name="test" transaction-type="JTA"> <jta-data-source>MySqlDS</jta-data-source> <properties> <property name="hibernate.hbm2ddl.auto" value="update" /> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" /> </properties> </persistence-unit> JDBC的驱动包也已经复制到JBoss安装目\server\lib下,MySqlDS的命名空间也没问题,配置文件中加了<use-java-context>false</use-java-context> 我试了下,如果把Bean的生成类型@Stateless去掉,则是可以部署的,一加上就报错,不知道为什么,下面贴下错误信息: org.jboss.deployers.spi.DeploymentException: Error deploying EJB_01.jar: Exception while processing container metadata for EJB: UserManagerBean in unit: EJB_01.jar at org.jboss.ejb3.deployers.Ejb3Deployer.deploy(Ejb3Deployer.java:196) at org.jboss.ejb3.deployers.Ejb3Deployer.deploy(Ejb3Deployer.java:99) at org.jboss.deployers.vfs.spi.deployer.AbstractVFSRealDeployer.internalDeploy(AbstractVFSRealDeployer.java:45) at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:50) at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:171) at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployersImpl.java:1439) at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1157) at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:1098) at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348) at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1631) at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934) at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1082) at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984) at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822) at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553) at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:781) at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:702) at org.jboss.system.server.profileservice.repository.MainDeployerAdapter.process(MainDeployerAdapter.java:117) at org.jboss.system.server.profileservice.hotdeploy.HDScanner.scan(HDScanner.java:362) at org.jboss.system.server.profileservice.hotdeploy.HDScanner.run(HDScanner.java:255) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317) at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:181) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:205) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:619) Caused by: java.lang.Exception: Exception while processing container metadata for EJB: UserManagerBean in unit: EJB_01.jar at org.jboss.ejb3.Ejb3Deployment.start(Ejb3Deployment.java:549) at org.jboss.ejb3.deployers.Ejb3Deployer.deploy(Ejb3Deployer.java:189) ... 28 more Caused by: java.lang.ArrayIndexOutOfBoundsException: 0 at org.jboss.injection.InjectionUtil.injectionTarget(InjectionUtil.java:314) at org.jboss.injection.PersistenceContextHandler.loadXml(PersistenceContextHandler.java:64) at org.jboss.ejb3.EJBContainer.processMetadata(EJBContainer.java:588) at org.jboss.ejb3.Ejb3Deployment.processEJBContainerMetadata(Ejb3Deployment.java:418) at org.jboss.ejb3.Ejb3Deployment.start(Ejb3Deployment.java:527) ... 29 more 01:48:04,661 WARN [HDScanner] Failed to process changes [解决办法] persistence.xml文件中: <persistence-unit name="test" transaction-type="JTA"> <jta-data-source>MySqlDS</jta-data-source> ...... 改为: persistence.xml文件中配置: <persistence-unit name="test" transaction-type="JTA"> <jta-data-source>java:MySqlDS</jta-data-source>