lizongbo at 618119.com 工作,生活,Android,前端,Linode,Ubuntu,nginx,java,apache,tomcat,Resin,mina,Hessian,XMPP,RPC

2007年11月2日

jbossCache在Tomcat中部署时出现javax.naming.NamingException: Context is read only

Filed under: cache,Java,JbossCache — 标签:, , , , , — lizongbo @ 11:41

出错信息为:

[code]
2007-11-02 11:33:41,471 ERROR [org.jboss.cache.transaction.DummyTransactionManager] – <binding of DummyTransactionManager failed>
javax.naming.NamingException: Context is read only
at org.apache.naming.NamingContext.checkWritable(NamingContext.java:903)

at org.apache.naming.NamingContext.bind(NamingContext.java:831)
at org.apache.naming.NamingContext.bind(NamingContext.java:171)
at org.apache.naming.NamingContext.bind(NamingContext.java:187)
at org.apache.naming.SelectorContext.bind(SelectorContext.java:171)
at javax.naming.InitialContext.bind(InitialContext.java:359)
at org.jboss.cache.transaction.DummyTransactionManager.getInstance(DummyTransactionManager.java:42)
at org.jboss.cache.transaction.GenericTransactionManagerLookup

.getTransactionManager (GenericTransactionManagerLookup.java:92)
at org.jboss.cache.CacheImpl.createTransactionManager(CacheImpl.java:660)
at org.jboss.cache.CacheImpl.internalStart(CacheImpl.java:726)
at org.jboss.cache.CacheImpl.start(CacheImpl.java:708)
at org.jboss.cache.DefaultCacheFactory.createCache(DefaultCacheFactory.java:79)
[/code]
这是因为我们通常是使用了JbossCache 自带的配置文件样本来进行配置的。
配置文件中默认是这样配置的:
<attribute name=”TransactionManagerLookupClass”>org.jboss.cache.transaction.GenericTransactionManagerLookup
</attribute>

而通过查看 org.jboss.cache.transaction.DummyTransactionManager.java的代码可以发现,
在创建TransactionManager的时候执行了一个Context。bind绑定操作。
出错信息用 log.error写入日志里:

代码为:[code]
public static DummyTransactionManager getInstance()
{
if (instance == null)
{
instance = new DummyTransactionManager();
try
{
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, “org.jboss.cache.transaction.DummyContextFactory”);
Context ctx = new InitialContext(p);
ctx.bind(“java:/TransactionManager”, instance);
ctx.bind(“UserTransaction”, new DummyUserTransaction(instance));
}
catch (NamingException e)
{
log.error(“binding of DummyTransactionManager failed”, e);
}
}
return instance;
}
[/code]

jboss官方网站有相关讨论:
http://jboss.org/?module=bb&op=viewtopic&t=98997

解决办法也很简单,就是将 TransactionManagerLookupClass指定为自己实现的MyTransactionManagerLookup

MyTransactionManagerLookup。java 代码如下 :
[code]

package com.lizongbo.jbosscache;

import org.jboss.cache.transaction.TransactionManagerLookup;
import javax.transaction.TransactionManager;
import org.jboss.cache.transaction.BatchModeTransactionManager;

public class MyTransactionManagerLookup implements TransactionManagerLookup {
public TransactionManager getTransactionManager() throws Exception {
return new BatchModeTransactionManager();
}

}
[/code]

修改后的配置文件为:

<!–
Configure the TransactionManager
–>
<attribute name=”TransactionManagerLookupClass”>com.lizongbo.jbosscache.MyTransactionManagerLookup</attribute>

Powered by WordPress