JBoss Wildfly 部署 Jersey Web Services 出错:JBAS011859:命名上下文是只读的。

3

我正在开发一个使用Jersey Servlet (1.18.1)的Java Web服务项目。当将EAR文件部署到Jboss WildFly (8.1.0)时,出现了以下错误,并且我不确定为什么会出错,因为这个相同的EAR文件在JBoss7 (7.1.1)中部署并且100%工作正常。
错误堆栈跟踪如下:

java.lang.UnsupportedOperationException: JBAS011859: Naming context is read-only
at org.jboss.as.naming.WritableServiceBasedNamingStore.requireOwner(WritableServiceBasedNamingStore.java:126)
at org.jboss.as.naming.WritableServiceBasedNamingStore.createSubcontext(WritableServiceBasedNamingStore.java:116)
at org.jboss.as.naming.NamingContext.createSubcontext(NamingContext.java:338)
at org.jboss.as.naming.InitialContext.createSubcontext(InitialContext.java:229)
at org.jboss.as.naming.NamingContext.createSubcontext(NamingContext.java:346)
at javax.naming.InitialContext.createSubcontext(InitialContext.java:464)
at com.sun.jersey.server.impl.cdi.CDIExtension$1.stepInto(CDIExtension.java:280)
3个回答

8

我在 JBoss 开发论坛上进行了一些研究,找到了答案。这是由于 Jersey 中存在一个错误,不允许将 JNDI 条目添加到 JVM 中。

要解决此问题,请将以下内容添加到 standalone.bat 文件中:

set "JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.jersey.server.impl.cdi.lookupExtensionInBeanManager=true"

或者属性文件:
com.sun.jersey.server.impl.cdi.lookupExtensionInBeanManager=true

感谢 Jboss Dev Thread:https://developer.jboss.org/message/817632#817632 - Ryan Zakariudakis
你是怎么解决这个问题的?我已经在我的Wildfly standalone.conf.bat文件中添加了设置,但不幸的是它并没有解决问题。你能详细说明一下你的解决方案吗?谢谢。 - Juri
类似问题:https://dev59.com/nnDYa4cB1Zd3GeqPGfxT - Juri
你必须将它添加到 standalone.bat 而不是 standalone.conf.bat。 - Ryan Zakariudakis

0

我能够处理这个问题。在命名jar中添加一个补丁。只需将 org.jboss.as.naming.service.NamingStoreService -> readOnly = true 改变一下。

完整的Java类 -

public class NamingStoreService implements Service {

private final boolean readOnly = false;
private volatile ServiceBasedNamingStore store;

public NamingStoreService() {
    this(false);
    System.out.println("Setting readOnly "+readOnly);
}

public NamingStoreService(boolean readOnly) {
    System.out.println("Setting readOnly "+readOnly);
}

/**
 * Creates the naming store if not provided by the constructor.
 *
 * @param context The start context
 * @throws StartException If any problems occur creating the context
 */
public void start(final StartContext context) throws StartException {
    if(store == null) {
        final ServiceRegistry serviceRegistry = context.getController().getServiceContainer();
        final ServiceName serviceNameBase = context.getController().getName();
        final ServiceTarget serviceTarget = context.getChildTarget();
        store = readOnly ? new ServiceBasedNamingStore(serviceRegistry, serviceNameBase) : new WritableServiceBasedNamingStore(serviceRegistry, serviceNameBase, serviceTarget);
    }
}

/**
 * Destroys the naming store.
 *
 * @param context The stop context
 */
public void stop(StopContext context) {
    if(store != null) {
        try {
            store.close();
            store = null;
        } catch (NamingException e) {
            throw MESSAGES.failedToDestroyRootContext(e);
        }
    }
}

/**
 * Get the context value.
 *
 * @return The naming store
 * @throws IllegalStateException
 */
public ServiceBasedNamingStore getValue() throws IllegalStateException {
    return store;
}
}

0
如果您正在使用Mac电脑,请在Jboss_home/bin目录下的standalone.conf文件中添加以下行:
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.jersey.server.impl.cdi.lookupExtensionInBeanManager=true"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接