Migrating EJB project from JBoss 4.x to 5.x

Woensdag 15 juli 2009  |  Door Bart Matthaei

Because this post could be useful to people using google, I'm posting this weblog article in English.

I spent a large portion of the day trying to migrate a EJB3 project from JBoss 4.x to 5.x. When I tried to deploy the project on JBoss 5.x, I got stuck in stacktrace-hell. Something about a NullPointerException while initializing a Session Bean.

When I tried to google for the problem, I only ran into people trying to reference a session bean from within the same session bean (see https://jira.jboss.org/jira/browse/EJBTHREE-1603). Then I tried something radical; I set up a new EAR / EJB project in Eclipse to see if I could reproduce the problem from scratch.

This is the relevant part of the stacktrace:

14:43:44,769 WARN  [Ejb3AnnotationHandler] JBMETA-4: did not find any bean meta data for annotation bean BeanOne, will create some
14:43:44,774 WARN  [Ejb3AnnotationHandler] JBMETA-4: did not find any bean meta data for annotation bean BeanTwo, will create some
14:43:44,778 WARN  [EJBRemoteHandler] EJBTHREE-1289: Using legacy EjbEncInjector, because mappedName for enc "env/demo.BeanTwo/one", field "one" is null (container.environmentRefGroup.annotatedEjbReferences = null)
14:43:44,819 INFO  [EJBContainer] STARTED EJB: demo.BeanOne ejbName: BeanOne
14:43:44,819 INFO  [JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:


14:43:44,869 INFO  [SessionSpecContainer] Starting jboss.j2ee:ear=TestEAR.ear,jar=TestEJB.jar,name=BeanTwo,service=EJB3
14:43:44,870 INFO  [SessionSpecContainer] Stopping jboss.j2ee:ear=TestEAR.ear,jar=TestEJB.jar,name=BeanTwo,service=EJB3
14:43:44,870 INFO  [EJBContainer] STOPPED EJB: demo.BeanTwo ejbName: BeanTwo
14:43:44,870 ERROR [AbstractKernelController] Error installing to Start: name=jboss.j2ee:ear=TestEAR.ear,jar=TestEJB.jar,name=BeanTwo,service=EJB3 state=Create
java.lang.NullPointerException
	at org.jboss.ejb3.proxy.factory.ProxyFactoryHelper.getRemoteAndBusinessRemoteInterfaces(ProxyFactoryHelper.java:613)
	at org.jboss.ejb3.proxy.factory.ProxyFactoryHelper.getJndiName(ProxyFactoryHelper.java:419)
	at org.jboss.ejb3.Ejb3Deployment.getEjbJndiName(Ejb3Deployment.java:403)
	at org.jboss.ejb3.EJBContainer.getEjbJndiName(EJBContainer.java:1521)
	at org.jboss.injection.EjbEncInjector.inject(EjbEncInjector.java:80)
	at org.jboss.ejb3.EJBContainer.lockedStart(EJBContainer.java:900)
	at org.jboss.ejb3.session.SessionContainer.lockedStart(SessionContainer.java:200)
	at org.jboss.ejb3.session.SessionSpecContainer.lockedStart(SessionSpecContainer.java:577)
	at org.jboss.ejb3.stateless.StatelessContainer.lockedStart(StatelessContainer.java:192)
	at org.jboss.ejb3.EJBContainer.start(EJBContainer.java:884)
[repeat till fade]
14:43:44,917 WARN  [WebServiceDeployerEJB] Ingore ejb deployment with null classname: org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData@553ef05c{BeanTwo}
14:43:44,917 WARN  [WebServiceDeployerEJB] Ingore ejb deployment with null classname: org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData@553edc76{BeanOne}
14:43:44,929 WARN  [HDScanner] Failed to process changes
org.jboss.deployers.client.spi.IncompleteDeploymentException: Summary of incomplete deployments (SEE PREVIOUS ERRORS FOR DETAILS):

DEPLOYMENTS IN ERROR:
  Deployment "jboss.j2ee:ear=TestEAR.ear,jar=TestEJB.jar,name=BeanTwo,service=EJB3" is in error due to the following reason(s): java.lang.NullPointerException

	at org.jboss.deployers.plugins.deployers.DeployersImpl.checkComplete(DeployersImpl.java:993)
	at org.jboss.deployers.plugins.deployers.DeployersImpl.checkComplete(DeployersImpl.java:939)
	at org.jboss.deployers.plugins.main.MainDeployerImpl.checkComplete(MainDeployerImpl.java:873)
	at org.jboss.system.server.profileservice.repository.MainDeployerAdapter.checkComplete(MainDeployerAdapter.java:128)
	at org.jboss.system.server.profileservice.hotdeploy.HDScanner.scan(HDScanner.java:369)
	[more lines of redundant stacktraces]

Where

INFO  [JndiSessionRegistrarBase] Binding the following Entries in Global JNDI: <empty>

is especially interesting. It seems our beans aren't being registered in JNDI.

The error could be reproduced with 2 simple beans (local interfaces omitted):


@Stateless
public class BeanOne implements BeanOneLocal {

}

@Stateless
public class BeanTwo implements BeanTwoLocal {

	@EJB
	private BeanOneLocal one;

}

I tried adding a name parameter to @Stateless, and a mappedName to @EJB, but it didn't help. However, when I created a new EAR / EJB project in Eclipse and deployed to JBoss 5, everything worked fine.

Only when I started comparing xml files, I found the actual problem. The older EJB jar contained the following ejb-jar.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar />

The new EJB jar contained a different ejb-jar.xml:


<ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:ejb="http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd" version="3.0">
</ejb-jar>

Adding the extra namespaces to the old project fixed everything. Pretty silly how some missing namespaces can screw up deployment, without triggering some useful warnings...



1 reactie(s) Geplaatst in: Java

Reacties

Andrea
7 januari 2010

Thank you!
Only your post saved me from beating my head against the wall.
I whish you all the best

Je reactie toevoegen

The content of this field is kept private and will not be shown publicly.