JBoss Wildfly with Jersey Web Services Deployment Error JBAS011859: Naming context is read-only

陌路散爱 提交于 2019-12-01 21:03:49
Ryan Zakariudakis

After Doing some research in JBoss Dev Forums i came across the answer. This is caused by a bug with Jersey which doesn't allow add JNDI entries into the JVM.

To fix it add the following to the standalone.bat:

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

or properties file:

com.sun.jersey.server.impl.cdi.lookupExtensionInBeanManager=true

I am able to manage this. Add a patch in naming jar. Just change org.jboss.as.naming.service.NamingStoreService -> readOnly = true

Full java class -

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;
}
}

If you are using Mac, add the below line to your standalone.conf file in Jboss_home/bin directory

JAVA_OPTS="$JAVA_OPTS -Dcom.sun.jersey.server.impl.cdi.lookupExtensionInBeanManager=true"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!