<div dir="ltr">Looks like your extension is being initialised before JNDI. There are two options:<br><br>- Use org.jboss.as.naming.service.BinderService to do the binding (there are lots of examples of how to use this in the Wildfly code base<div>- Create a custom service that depends upon the appropriate naming subsystem services (namely DefaultNamespaceContextSelectorService.SERVICE_NAME), and do the bind/unbind in the services start/stop method. This will make sure the naming subsystem is up before the bind takes place. </div><div><br></div><div>Stuart </div></div><br><div class="gmail_quote">On Mon, 16 Mar 2015 at 08:37 John Mazzitelli &lt;<a href="mailto:mazz@redhat.com">mazz@redhat.com</a>&gt; wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I have a custom subsystem extension I&#39;m deploying in Wildfly 8.2. I hit a problem when trying to bind an object to JNDI.<br>
<br>
In my AbstractAddStepHandler.<u></u>performRuntime() (the Subsystem Add handler), I want to bind an object to JNDI, like this:<br>
<br>
  InitialContext initialContext = new InitialContext();<br>
  WritableServiceBasedNamingStor<u></u>e.pushOwner(context.<u></u>getServiceTarget());<br>
    try {<br>
      initialContext.bind(jndiName, jndiObject); // &lt;--- this sometimes throws exception you see below<br>
    } finally {<br>
      WritableServiceBasedNamingStor<u></u>e.popOwner();<br>
    }<br>
<br>
where &quot;context&quot; is the first parameter passed to the performRuntime() method, and &quot;jndiName&quot; is &quot;java:global/example/demo/<u></u>myname&quot; and &quot;jndiObject&quot; is just a java.lang.String, like &quot;hello&quot;.<br>
<br>
The use of WritableServiceBasedNamingStor<u></u>e is recommended on the wiki: <a href="https://docs.jboss.org/author/display/WFLY8/JNDI+Reference" target="_blank">https://docs.jboss.org/author/<u></u>display/WFLY8/JNDI+Reference</a> - though I have no idea what it is doing :)<br>
<br>
The problem is - each time I start my wildfly server, sometimes it works, other times it doesn&#39;t. It is as if there is a race condition somewhere on startup of the wildfly server. If it works, my JNDI object is bound properly; when it fails, this bombs with the exception I show below.<br>
<br>
Anyone know what the problem is and how to fix?<br>
<br>
====<br>
<br>
javax.naming.<u></u>NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial<br>
        at javax.naming.spi.<u></u>NamingManager.<u></u>getInitialContext(<u></u>NamingManager.java:662) [rt.jar:1.8.0_31]<br>
        at javax.naming.InitialContext.<u></u>getDefaultInitCtx(<u></u>InitialContext.java:313) [rt.jar:1.8.0_31]<br>
        at javax.naming.InitialContext.<u></u>getURLOrDefaultInitCtx(<u></u>InitialContext.java:350) [rt.jar:1.8.0_31]<br>
        at javax.naming.InitialContext.<u></u>bind(InitialContext.java:425) [rt.jar:1.8.0_31]<br>
        at org.demo.extension.<u></u>SubsystemAdd.performRuntime(<u></u>SubsystemAdd.java:153)<br>
        at org.jboss.as.controller.<u></u>AbstractAddStepHandler$1.<u></u>execute(<u></u>AbstractAddStepHandler.java:<u></u>75) [wildfly-controller-8.2.0.<u></u>Final.jar:8.2.0.Final]<br>
        at org.jboss.as.controller.<u></u>AbstractOperationContext.<u></u>executeStep(<u></u>AbstractOperationContext.java:<u></u>660) [wildfly-controller-8.2.0.<u></u>Final.jar:8.2.0.Final]<br>
        at org.jboss.as.controller.<u></u>AbstractOperationContext.<u></u>doCompleteStep(<u></u>AbstractOperationContext.java:<u></u>501) [wildfly-controller-8.2.0.<u></u>Final.jar:8.2.0.Final]<br>
        at org.jboss.as.controller.<u></u>AbstractOperationContext.<u></u>completeStepInternal(<u></u>AbstractOperationContext.java:<u></u>298) [wildfly-controller-8.2.0.<u></u>Final.jar:8.2.0.Final]<br>
        at org.jboss.as.controller.<u></u>AbstractOperationContext.<u></u>executeOperation(<u></u>AbstractOperationContext.java:<u></u>293) [wildfly-controller-8.2.0.<u></u>Final.jar:8.2.0.Final]<br>
        at org.jboss.as.controller.<u></u>ParallelBootOperationStepHandl<u></u>er$ParallelBootTask.run(<u></u>ParallelBootOperationStepHandl<u></u>er.java:354) [wildfly-controller-8.2.0.<u></u>Final.jar:8.2.0.Final]<br>
        at java.util.concurrent.<u></u>ThreadPoolExecutor.runWorker(<u></u>ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_31]<br>
        at java.util.concurrent.<u></u>ThreadPoolExecutor$Worker.run(<u></u>ThreadPoolExecutor.java:617) [rt.jar:1.8.0_31]<br>
        at java.lang.Thread.run(Thread.<u></u>java:745) [rt.jar:1.8.0_31]<br>
        at org.jboss.threads.JBossThread.<u></u>run(JBossThread.java:122) [jboss-threads-2.1.1.Final.<u></u>jar:2.1.1.Final]<br>
______________________________<u></u>_________________<br>
wildfly-dev mailing list<br>
<a href="mailto:wildfly-dev@lists.jboss.org" target="_blank">wildfly-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/wildfly-dev" target="_blank">https://lists.jboss.org/<u></u>mailman/listinfo/wildfly-dev</a><br>
</blockquote></div>