JavaEE 6:javax.naming.NameAlreadyBoundException:使用重新绑定来覆盖
我有一个由两个 EJB 实现的业务接口。
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 时,出现以下错误:
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
有人可以帮我理解为什么会出现此错误吗?怎么解决呢?
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;
// ...
}
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
默认情况下,会自动应用 GlassFish Server 特定的默认 JNDI 名称以实现向后兼容性。因此,
com.transbinary.imdb.service.UserManagementService
是UserManagementService
接口的两个实现的默认 JNDI 名称。这就是为什么我收到 javax.naming.NameAlreadyBoundException 异常的原因。但由于 EJB 3.1 规范定义了可移植的 EJB JNDI 名称,因此对 GlassFish Server 特定 JNDI 名称的需求较少。
要禁用 EJB 模块的 GlassFish Server 特定 JNDI 名称,请将
disable-nonportable-jndi-names
元素的值设置为true
。默认值为false
。它解决了问题。
资源:http://wikis.oracle.com/display/GlassFish/Developer+Handoff+to+QA+for+EJB-8+%28Option+to+disable+GlassFish-specific+JNDI%29
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 ofUserManagementService
interface. Which was why I was getttingjavax.naming.NameAlreadyBoundException
exception.But because the EJB 3.1 specification defines portable EJB JNDI names, there is less need for GlassFish Server specific JNDI names.
To disable GlassFish Server specific JNDI names for an EJB module, set the value of
disable-nonportable-jndi-names
element totrue
. The default isfalse
.It solved the problem.
Resource: http://wikis.oracle.com/display/GlassFish/Developer+Handoff+to+QA+for+EJB-8+%28Option+to+disable+GlassFish-specific+JNDI%29
GlassFish 重新启动。 (这对我有用。)
GlassFish restart. (It worked for me.)
我也遇到了同样的异常。
就我而言,我将代码从
@Stateless(mappedName = "whatever")
更改为
@Stateless(name = "whatever")
它解决了我的问题
I got this same exception.
In my case I changed my code from
@Stateless(mappedName = "whatever")
to instead be
@Stateless(name = "whatever")
and it solved my issue
使用重新绑定而不是绑定,它应该可以工作
Make use of rebind instead of bind and it should work
就我而言,我使用的是 JBoss5.1GA,并且我有两个 EJB 实现了一个通用的本地业务接口...
我遵循@Christo Smal 建议的想法,它对我有用...另一个观察:我正在部署一个Ear,其中包含两个不同 EJB jar 中的两个 EJB;例如:
In my case, i was using JBoss5.1GA and i had two EJBs implementing a common local Business Interface...
I Follow the idea suggested by @Christo Smal, and it work for me.... Another Observation: I was deploying an ear which contains the two EJBs at two differents EJB jars; e.g: