0

My tomcat(7.0.34) shows error as

Creation of the naming context failed: javax.naming.OperationNotSupportedException: Context is read only

when it starts up. But I don't know why? And how to fix it?

UPDATE

the log:

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
4

3 回答 3

3

The Java EE spec states in Section 5.3.4 that the Naming context must be read-only and that OperationNotSupportedExceptions must be thrown on change requests. Unfortunatly, this does not directly answer your question, but may be a hint

Quote from the spec:

The container must ensure that the application component instances have only read access to their naming context. The container must throw the javax.naming.OperationNotSupportedException from all the methods of the javax.naming.Context interface that modify the environment naming context and its subcontexts.

于 2013-03-11T15:35:02.810 回答
1

We recently upgraded our tomcat instance from Tomcat 5 to Tomcat 7. The existing code looks something like this: ​

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

The last two lines were obviously meant to release the resources but this is not acceptable to Tomcat (see https://bz.apache.org/bugzilla/show_bug.cgi?id=51744). If you cannot change your code then the work-around is to apply jndiExceptionOnFailedWrite to the context (https://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Standard_Implementation), e.g.

<Context jndiExceptionOnFailedWrite="false">
于 2015-09-24T01:43:11.427 回答
-1

I recently got the same error. It was due to a config error where my JNDI server url was missing a slash.

So I had

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

Instead of

java.naming.provider.url=tcp://10.211.55.3:7222
于 2013-11-06T06:41:24.397 回答