无法在 Weblogic 中查找 TimerManager 资源

Unable to lookup TimerManager resources in Weblogic

我试图在 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>

还有我的 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 上下文中的对象之后,它似乎确实忽略了资源引用。我会进一步调查。

这是完整的堆栈跟踪:

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.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.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.access0(DeploymentReceiverCallbackDeliverer.java:12)
at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.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.resource-ref 标签!现在一切正常。我什至不再需要 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");
    // ...
  }
}