本文介绍了JavaEE 6:javax.naming.NameAlreadyBoundException:使用重新绑定重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由两个EJB实现的业务接口。

I have a business interface being implemented by two EJBs.

UserManagementService

@Remote
public interface UserManagementService {
    // ...
}

UserManagementServiceJpaImpl

@Stateless(name="userManagementServiceJpaImpl")
public class UserManagementServiceJpaImpl implements UserManagementService {

    @EJB(beanName="userManagementDaoJpaImpl")
    private UserManagementDao userManagementDao;

    // ...
}

UserManagementServiceMockImpl

@Stateless(name="userManagementServiceMockImpl")
public class UserManagementServiceMockImpl implements UserManagementService {

    @EJB(beanName="userManagementDaoMockImpl")
    private UserManagementDao userManagementDao;

    // ...

}

将应用程序部署到Glassfish 3.1时,出现以下错误:

When I deploy the application to Glassfish 3.1 I get the following error:

java.lang.RuntimeException: Error while binding JNDI name com.transbinary.imdb.service.UserManagementService for EJB : userManagementServiceMockImpl
    at com.sun.ejb.containers.BaseContainer.initializeHome(BaseContainer.java:1550)
    at com.sun.ejb.containers.StatelessSessionContainer.initializeHome(StatelessSessionContainer.java:202)
    at com.sun.ejb.containers.ContainerFactoryImpl.createContainer(ContainerFactoryImpl.java:167)
    at org.glassfish.ejb.startup.EjbApplication.loadContainers(EjbApplication.java:234)
    at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:290)
    at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:101)
    at org.glassfish.internal.data.ModuleInfo.load(ModuleInfo.java:186)
    at org.glassfish.internal.data.ApplicationInfo.load(ApplicationInfo.java:249)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:460)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
    at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:370)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:360)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:370)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1067)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:96)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1247)
    at org.glassfish.deployment.autodeploy.AutoOperation.run(AutoOperation.java:145)
    at org.glassfish.deployment.autodeploy.AutoDeployer.deploy(AutoDeployer.java:577)
    at org.glassfish.deployment.autodeploy.AutoDeployer.deployAll(AutoDeployer.java:463)
    at org.glassfish.deployment.autodeploy.AutoDeployer.run(AutoDeployer.java:395)
    at org.glassfish.deployment.autodeploy.AutoDeployer.run(AutoDeployer.java:380)
    at org.glassfish.deployment.autodeploy.AutoDeployService$1.run(AutoDeployService.java:213)
    at java.util.TimerThread.mainLoop(Timer.java:512)
    at java.util.TimerThread.run(Timer.java:462)
Caused by: javax.naming.NameAlreadyBoundException: Use rebind to override
    at com.sun.enterprise.naming.impl.TransientContext.doBindOrRebind(TransientContext.java:333)
    at com.sun.enterprise.naming.impl.TransientContext.bind(TransientContext.java:268)
    at com.sun.enterprise.naming.impl.SerialContextProviderImpl.bind(SerialContextProviderImpl.java:98)
    at com.sun.enterprise.naming.impl.LocalSerialContextProviderImpl.bind(LocalSerialContextProviderImpl.java:99)
    at com.sun.enterprise.naming.impl.SerialContext.bind(SerialContext.java:672)
    at com.sun.enterprise.naming.impl.SerialContext.bind(SerialContext.java:689)
    at javax.naming.InitialContext.bind(InitialContext.java:404)
    at javax.naming.InitialContext.bind(InitialContext.java:404)
    at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.publishObject(GlassfishNamingManagerImpl.java:208)
    at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.publishObject(GlassfishNamingManagerImpl.java:189)
    at com.sun.ejb.containers.BaseContainer$JndiInfo.publish(BaseContainer.java:5608)
    at com.sun.ejb.containers.BaseContainer.initializeHome(BaseContainer.java:1535)
    ... 23 more

有人可以帮助我了解为什么会收到此错误以及如何解决该错误吗?

Could someone help me understand why am I getting this error and how to resolve it?

推荐答案

默认情况下,默认情况下,GlassFish Server特定的默认JNDI名称将自动应用于反向联合。兼容性。因此, com.transbinary.imdb.service.UserManagementService UserManagementService 接口的两个实现的默认JNDI名称。这就是为什么我得到 javax.naming.NameAlreadyBoundException 异常的原因。

By default GlassFish Server specific default JNDI names are applied automatically for backward compatibility. So com.transbinary.imdb.service.UserManagementService is the the default JNDI name for both the implementations of UserManagementService interface. Which was why I was gettting javax.naming.NameAlreadyBoundException exception.

但是因为EJB 3.1规范定义了可移植EJB。 JNDI名称,对于GlassFish Server特定的JNDI名称的需求减少。

But because the EJB 3.1 specification defines portable EJB JNDI names, there is less need for GlassFish Server specific JNDI names.

要为EJB模块禁用GlassFish Server特定的JNDI名称,请设置 disable-nonportable-jndi-names 元素为 true 。默认值为 false

To disable GlassFish Server specific JNDI names for an EJB module, set the value of disable-nonportable-jndi-names element to true. The default is false.

已解决了问题。

资源:

这篇关于JavaEE 6:javax.naming.NameAlreadyBoundException:使用重新绑定重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-05 05:42