【问题标题】:What could cause "javax.naming.OperationNotSupportedException" when tomcat startuptomcat启动时可能导致“javax.naming.OperationNotSupportedException”的原因
【发布时间】:2013-03-11 13:46:36
【问题描述】:

我的 tomcat(7.0.34) 显示错误为

创建命名上下文失败: javax.naming.OperationNotSupportedException:上下文是只读的

当它启动时。但我不知道为什么?以及如何解决?

更新

日志:

Info: Starting Servlet Engine: Apache Tomcat/7.0.34
Mar 11, 2013 9:43:18 PM org.apache.catalina.core.NamingContextListener lifecycleEvent
Critical: Creation of the naming context failed: javax.naming.OperationNotSupportedException: Context is read only
Mar 11, 2013 9:43:18 PM org.apache.coyote.AbstractProtocol start
Info: Starting ProtocolHandler ["ajp-bio-8081"]
Mar 11, 2013 9:43:18 PM org.apache.catalina.core.StandardService startInternal
Info: Starting service ChongWuXingQiu
Mar 11, 2013 9:43:18 PM org.apache.catalina.core.StandardEngine startInternal
Info: Starting Servlet Engine: Apache Tomcat/7.0.34
Mar 11, 2013 9:43:18 PM org.apache.catalina.core.NamingContextListener lifecycleEvent
Critical: Creation of the naming context failed: javax.naming.OperationNotSupportedException: Context is read only
Mar 11, 2013 9:43:18 PM org.apache.coyote.AbstractProtocol start
Info: Starting ProtocolHandler ["ajp-bio-8082"]
Mar 11, 2013 9:43:18 PM org.apache.catalina.startup.Catalina start
Info: Server startup in 1753 ms

【问题讨论】:

  • 你能在错误周围显示更多的堆栈跟踪信息吗? (假设有一些)

标签: jakarta-ee tomcat jndi


【解决方案1】:

Java EE 规范在第 5.3.4 节中指出,命名上下文必须是只读的,并且必须在更改请求上抛出 OperationNotSupportedExceptions。不幸的是,这并不能直接回答您的问题,但可能是一个提示

引用自spec

容器必须确保应用程序组件实例对其命名上下文只有读取权限。容器必须从修改环境命名上下文及其子上下文的 javax.naming.Context 接口的所有方法中抛出 javax.naming.OperationNotSupportedException。

【讨论】:

    【解决方案2】:

    我们最近将我们的 tomcat 实例从 Tomcat 5 升级到了 Tomcat 7。现有代码如下所示:​

    Context initCtx;
    initCtx = new InitialContext();
    Context envCtx = (Context) initCtx.lookup("java:comp/env");
    strSMTPFrom = (String) envCtx.lookup("env/SMTP_From");
    envCtx.close();
    envCtx = null;
    

    最后两行显然是为了释放资源,但这对 Tomcat 来说是不可接受的(参见https://bz.apache.org/bugzilla/show_bug.cgi?id=51744)。如果您无法更改代码,则解决方法是将 jndiExceptionOnFailedWrite 应用于上下文 (https://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Standard_Implementation),例如

    <Context jndiExceptionOnFailedWrite="false">
    

    【讨论】:

      【解决方案3】:

      我最近遇到了同样的错误。这是由于配置错误导致我的 JNDI 服务器 url 缺少斜杠。

      所以我有

      java.naming.provider.url=tcp:/10.211.55.3:7222
      

      代替

      java.naming.provider.url=tcp://10.211.55.3:7222
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-02-25
        • 1970-01-01
        • 1970-01-01
        • 2010-11-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多