[jboss-user] [EJB 3.0] - Re: can any one help me - having a bad day with ejb3 server

wiggy do-not-reply at jboss.com
Mon May 28 12:32:51 EDT 2007


wolfgang, 

I changed my 4.2 server ejb to 


  | 
  | @Stateless
  | public class HelloUserBean implements HelloUserRemote
  | {
  | 
explicitly as the interface that has the @Remote annotation and deploy to the 4.2 server.

if i then do the basic jndi lookup from the embedded server then i get a valid reference and the test call works.

however if i try to use DI in the embedded server to get a reference to the ejb it doesnt work  and i get  


anonymous wrote : 
  | 59,433 INFO  [MCKernelAbstraction] installing bean: jboss.j2ee:jar=bin,name=TestBean,service=EJB3 with dependencies:
  | 17:22:59,603 INFO  [EJBContainer] STARTED EJB: TestBean ejbName: TestBean
  | 17:22:59,623 INFO  [MCKernelAbstraction] installing bean: jboss.j2ee:jar=classes,name=HelloUserBean,service=EJB3 with dependencies:
  | 17:22:59,633 INFO  [EJBContainer] STARTED EJB: app.HelloUserBean ejbName: HelloUserBean
  | Exception in thread "main" java.lang.NullPointerException
  | 	at ClientApp.init(ClientApp.java:75)
  | 	at ClientApp.main(ClientApp.java:61)
  | 

from test code now looking like 


  | /**
  |  * 
  |  */
  | 	import java.util.Hashtable;
  | 
  | import javax.ejb.EJB;
  | import javax.naming.InitialContext;
  | 
  | 
  | import org.apache.log4j.Level;
  | import org.apache.log4j.Logger;
  | import org.jboss.ejb3.embedded.EJB3StandaloneBootstrap;
  | 
  | import app.client.HelloUser;
  | import app.client.HelloUserRemote;
  | 
  | /**
  |  * @author Will
  |  *
  |  */
  | public class ClientApp 
  | {
  | 	@EJB (name="HelloUserRemote")
  | 	public HelloUserRemote tstHandler;
  | 
  | 	@EJB (name="Test")
  | 	public Test test;
  | 
  | 	public ClientApp () {}
  | 
  | 	public static void main(String[] args) throws Exception 
  | 	{
  | 
  | 		Logger log = Logger.getLogger(ClientApp.class);
  | 		log.setLevel(Level.DEBUG);
  | 		//log.debug("Welcome to Wills App");
  | 		
  | 		// Boot the JBoss Microcontainer with EJB3 settings, automatically
  | 		// loads ejb3-interceptors-aop.xml and embedded-jboss-beans.xml
  | 	    EJB3StandaloneBootstrap.boot(null);
  | 
  | 	    // Deploy custom stateless beans (datasource, mostly)
  | 		//EJB3StandaloneBootstrap.deployXmlResource("META-INF/NeilsApp-beans.xml");
  | 
  | 		// Deploy all EJBs found on classpath (fast, scans build directory)
  | 		// This is a relative location, matching the substring end of one
  | 		// of java.class.path locations. Print out the value of
  | 		// System.getProperty("java.class.path") to see all paths.
  | 	    EJB3StandaloneBootstrap.scanClasspath();
  | 
  | 	    InitialContext ctx = getInitialContext();
  | 
  | 	    
  | 	    // Look up the stateless TestHandler EJB
  | 		//HelloUserRemote tstHandlerLoc = (HelloUserRemote) ctx.lookup("HelloUserBean/remote");
  | 		// Call the stateless EJB
  | 		//String message = tstHandlerLoc.sayHello("hello Will");
  | 		
  | 	    //try dependency injection!
  | 		//new TestBean().message("hi there");
  | 		new ClientApp().init ();
  | 		
  | 	    
  | 
  | 		
  | 		//Shut down EJB container
  | 		EJB3StandaloneBootstrap.shutdown();
  | 
  | 	}
  | 	
  | 	public void init()
  | 	{
  | 		//trigger the DI for test
  | 		//test.message("try again");
  | 		tstHandler.sayHello("hello there via DI");
  | 	}
  | 	...
  | 	
  | 

my tstHandler is a DI injected reference in the top of the clientApp class.  

This gets the null pointer ref - hence the embedded container DI isnt working - but my jndi hard work version does - why cant the DI pick up the remote reference in the embedded app version ? (I new i think that 4.2AS didnt have the application client loader - hence the use of the embedded container to run my client class.

Wiggy



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

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



More information about the jboss-user mailing list