[jboss-user] [EJB 3.0] - Re: JUnit testing EJBs: NoInitialContextException

ALRubinger do-not-reply at jboss.com
Thu Sep 7 14:20:49 EDT 2006


>From within the container, your InitialContext will be configured properly when using the default constructor.  From a remote client (another JVM, like your JUnit Test), this isn't the case, and you'll have to get your context:


  | Hashtable<String, String> props= new Hashtable<String, String>(); 
  | props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
  | props.put(Context.PROVIDER_URL,"jnp://localhost:1099" );
  | props.put(Context.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces" );
  | Context ctx = new InitialContext( props );
  | 

..replacing the host and port in Context.PROVIDER_URL with something appropriate.

Dependency injection...you'll have to do a lookup for that bean using the Context above - you'll only be able to inject container-managed resources into other container-managed resources.

S,
ALR

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3970166#3970166

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3970166



More information about the jboss-user mailing list