0

在 Web.xml 我有:

<resource-ref>
    <res-ref-name>java:/comp/env/tm/TimerManager</res-ref-name>
    <res-type>commonj.timers.TimerManager</res-type>
    <res-auth>Container</res-auth>
    <res-sharing-scope>Unshareable</res-sharing-scope>
</resource-ref>

在我的java代码中:

    TimerManager tm = (TimerManager) ic.lookup("tm/TimerManager");
tm.schedule(new CleanupListener(), 0, 10*1000); // CleanupListener class is my TimerListener

因此,当我运行代码时,计时器成功启动,但在代码崩溃后立即出现以下异常:

javax.naming.ConfigurationException:NamingManager.getURLContext 找不到此方案的工厂:java

我不知道为什么。当我用这个更改查找时:TimerManager tm = (TimerManager) ic.lookup("java:/comp/env/tm/TimerManager"); 这是最糟糕的,计时器永远不会启动,我确实有以下异常: db.common.util.ServiceLocatorException: javax.naming.ConfigurationException: NamingManager.getURLContext 找不到该方案的工厂: 爪哇

请帮忙,非常重要。谢谢

4

3 回答 3

0

尝试使用

java:comp/env/tm/TimerManager

代替

java:/comp/env/tm/TimerManager

如果那没有帮助。请发布您的完整部署描述符和绑定文件(web.xml 以及 ibm-web-bnd.xml 或 ibm-web-bnd.xmi),以确保此文件中的配置正确。

感谢您发布文件。我认为问题在于 web.xml 3.0 版与 ibm-web-bnd.xmi 不兼容。尝试将 web.xml 版本 3.0 与 ibm-web-bnd.xml 一起使用,或者将早期版本的 web.xml 与 ibm-web-bnd.xmi 一起使用。

于 2017-04-13T21:42:01.320 回答
0

您还原了有效的语法。

在 web.xml 中:

<res-ref-name>tm/TimerManager</res-ref-name>

在源代码中:

ic.lookup("java:comp/env/tm/TimerManager")
于 2018-05-31T00:03:45.530 回答
0

这是 web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.0"
    xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>testApp</display-name>

    <welcome-file-list>
        <welcome-file>/WEB-INF/jsp/index.jsp</welcome-file>
    </welcome-file-list>

    <servlet>
        <servlet-name>test</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value></param-value>
        </init-param>
    </servlet>

    <listener>
        <listener-class>
            or.tc.pack.context.listener.TestWebContextListener
        </listener-class>
    </listener>

    <!-- The master configuration file for this Spring web application -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/context/testway/webApplication-config-local.xml
        </param-value>
    </context-param>

    <!-- Loads the Spring web application context -->
    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>

    <servlet-mapping>
        <servlet-name>test</servlet-name>
        <url-pattern>/services/eng/*</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>test</servlet-name>
        <url-pattern>/services/fra/*</url-pattern>
    </servlet-mapping>

    <session-config>
        <session-timeout>480</session-timeout>
    </session-config>

    <resource-ref id="ResourceRef_1288099140976">
        <description>
        Business Update queue</description>
        <res-ref-name>jms/ZZZZ_ZZ_ZZZZ_BUS_UPD</res-ref-name>
        <res-type>javax.jms.Queue</res-type>
        <res-auth>Application</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>

    <resource-ref>
        <description>
        </description>
        <res-ref-name>java:comp/env/tm/TimerManager</res-ref-name>
        <res-type>commonj.timers.TimerManager</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Unshareable</res-sharing-scope>
    </resource-ref>

</web-app>

这是 ibm-web-bnd.xmi:

<?xml version="1.0" encoding="UTF-8"?>
<webappbnd:WebAppBinding xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:webappbnd="webappbnd.xmi" xmi:id="WebAppBinding_1263831088044">
  <webapp href="WEB-INF/web.xml#WebApp_ID"/>
  <resRefBindings xmi:id="ResourceRefBinding_1288099140976" jndiName="customs/commercial/tal/jms/ZZZZ_ZZ_ZZZZ_BUS_UPD">
    <bindingResourceRef href="WEB-INF/web.xml#ResourceRef_1288099140976"/>
  </resRefBindings>
</webappbnd:WebAppBinding>
于 2017-04-18T16:41:24.093 回答