我试图在Weblogic企业应用程序上查找TimerManager资源,但无论我尝试什么,我总是得到NameNotFoundException。我在网上看了很多不同的解决方案,但还没有找到一个有效的:
我的ejb-jar.xml:
<ejb-jar>
<enterprise-beans>
<session>
<ejb-name>TimerBean</ejb-name>
<remote>ejb.generated.TimerBeanRemote</remote>
<local>ejb.generated.TimerBeanLocal</local>
<home>ejb.generated.TimerBeanHomeRemote</home>
<local-home>ejb.generated.TimerBeanHomeLocal</local-home>
<ejb-class>ejb.TimerBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<resource-ref>
<res-ref-name>tm/TimerController</res-ref-name>
<res-type>commonj.timers.TimerManager</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Unshareable</res-sharing-scope>
</resource-ref>
</session>
</enterprise-beans>
</ejb-jar>
我weblogic-ejb-jar.xml :
<weblogic-ejb-jar>
<weblogic-enterprise-bean>
<ejb-name>TimerBean</ejb-name>
<local-jndi-name>TimerBeanLocal</local-jndi-name>
<jndi-name>ejb/TimerBeanRemote</jndi-name>
<dispatch-policy>ejb-workmanagement</dispatch-policy>
<reference-descriptor>
<resource-description>
<res-ref-name>tm/TimerController</res-ref-name>
<jndi-name>TimerController</jndi-name>
<res-type>commonj.timers.TimerManager</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Unshareable</res-sharing-scope>
</resource-description>
</reference-descriptor>
</weblogic-ejb-jar>
And my Bean:
// xdocklet generated.
public abstract class TimerBean implements SessionBean {
public void ejbCreate() {
Context context = new InitialContext();
TimerManager mgr = (TimerManager) context.lookup("java:comp/env/tm/TimerController");
// ...
}
}
我试着查找"java:comp/env/tm/TimerController"
, "java:/comp/env/tm/TimerController"
, "tm/TimerController"
…似乎没有什么工作,我总是以一个NameNotFoundException结束,总是从整个字符串,除了java:
部分,作为剩余的名称(即它根本找不到任何东西)。
编辑似乎我的TimerController资源不存在于Weblogic的jndi树页面。
edit2在使用context.list("java:comp/env")
列出java:comp/env
上下文中的对象后,似乎确实忽略了资源ref。我将进一步调查。
javax.naming.NameNotFoundException: While trying to look up comp/env/tm/TimerController in /app/ejb/my-app-ejb-1.0.0-SNAPSHOT.jar#TimerBean.; remaining name 'comp/env/tm/TimerController'
at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:1139)
at weblogic.jndi.internal.ApplicationNamingNode.lookup(ApplicationNamingNode.java:144)
at weblogic.jndi.internal.WLEventContextImpl.lookup(WLEventContextImpl.java:254)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:380)
at weblogic.jndi.factories.java.ReadOnlyContextWrapper.lookup(ReadOnlyContextWrapper.java:45)
at weblogic.jndi.internal.AbstractURLContext.lookup(AbstractURLContext.java:130)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at ejb.TimerBean.ejbCreate(TimerBean.java:55)
at ejb.TimerBean_sxsqua_Impl.ejbCreate(TimerBean_sxsqua_Impl.java:162)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at weblogic.ejb.container.pool.StatelessSessionPool.createBean(StatelessSessionPool.java:205)
at weblogic.ejb.container.pool.Pool.createInitialBeans(Pool.java:300)
at weblogic.ejb.container.manager.StatelessManager.initializePool(StatelessManager.java:444)
at weblogic.ejb.container.deployer.EJBDeployer.initializePools(EJBDeployer.java:1546)
at weblogic.ejb.container.deployer.EJBDeployer.start(EJBDeployer.java:1377)
at weblogic.ejb.container.deployer.EJBModule.start(EJBModule.java:589)
at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:117)
at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:204)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:37)
at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:60)
at weblogic.application.internal.flow.StartModulesFlow.activate(StartModulesFlow.java:27)
at weblogic.application.internal.BaseDeployment$2.next(BaseDeployment.java:635)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:37)
at weblogic.application.internal.BaseDeployment.activate(BaseDeployment.java:212)
at weblogic.application.internal.EarDeployment.activate(EarDeployment.java:16)
at weblogic.application.internal.DeploymentStateChecker.activate(DeploymentStateChecker.java:162)
at weblogic.deploy.internal.targetserver.AppContainerInvoker.activate(AppContainerInvoker.java:79)
at weblogic.deploy.internal.targetserver.operations.AbstractOperation.activate(AbstractOperation.java:569)
at weblogic.deploy.internal.targetserver.operations.ActivateOperation.activateDeployment(ActivateOperation.java:140)
at weblogic.deploy.internal.targetserver.operations.ActivateOperation.doCommit(ActivateOperation.java:106)
at weblogic.deploy.internal.targetserver.operations.StartOperation.doCommit(StartOperation.java:143)
at weblogic.deploy.internal.targetserver.operations.AbstractOperation.commit(AbstractOperation.java:323)
at weblogic.deploy.internal.targetserver.DeploymentManager.handleDeploymentCommit(DeploymentManager.java:820)
at weblogic.deploy.internal.targetserver.DeploymentManager.activateDeploymentList(DeploymentManager.java:1227)
at weblogic.deploy.internal.targetserver.DeploymentManager.handleCommit(DeploymentManager.java:436)
at weblogic.deploy.internal.targetserver.DeploymentServiceDispatcher.commit(DeploymentServiceDispatcher.java:163)
at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.doCommitCallback(DeploymentReceiverCallbackDeliverer.java:181)
at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.access$100(DeploymentReceiverCallbackDeliverer.java:12)
at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer$2.run(DeploymentReceiverCallbackDeliverer.java:67)
at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:516)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
终于解决了!!!!
表明问题出在xdoclet生成上。我错过了@ejb。资源引用标记!现在一切都正常了。我甚至不需要ejb-jar.xml和weblogic-ejb-jar.xml了。
下面是完整的工作Bean:
/**
* @ejb.bean
* name="TimerBean"
* jndi, home, remote config
* @ejb.resource-ref
* res-ref-name="TimerController"
* res-type="commonj.timers.TimerManager"
* res-auth="Container"
* res-sharing-scope="Shareable"
*/
public abstract class TimerBean implements SessionBean {
public void ejbCreate() {
Context context = new InitialContext();
TimerManager mgr = (TimerManager) context.lookup("java:comp/env/TimerController");
// ...
}
}