Today I was given this exception
Caused by: javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext [Root exception is java.lang.NullPointerException] at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:276) at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:430) ... 23 more
I tried remotely accessing ejb, the violation code was
Context c = new InitialContext();
I saw this exception before and fixed it, but I couldn’t remember exactly how I did it. I knew that I needed to set some environment variables for the source, contextual URL and the service provider or some similar materials.
In fact, I managed to find the code that I used to fix this problem the last time I had it, it looks like this.
Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.enterprise.naming.SerialInitContextFactory"); env.put(Context.PROVIDER_URL, "localhost:1099"); Context c = new InitialContext(env);
My question is, how can you find out which original factory context to use? I wrote an ejb module for our database that runs on Glassfish v3, by no means received any hint that, of course, I should use com.sun.enterprise.naming.SerialInitContextFactory , I mean that it so obvious. Who makes these contextual factories? Who decides which one I need to use and why? Why is there no list showing which one is required for different purposes? It seems that someone has gone astray to make the most impenetrable and mysterious way to access a resource that is humanly possible. Or I didn’t understand anything at all, or I lack a huge amount of knowledge.
I would very much like to receive some enlightenment on this issue.
Thanks to everyone.
source share