[GLASSFISH-1358] Can not resolve EJBs in ServletContextListener Created: 22/Oct/06  Updated: 06/Mar/12

Status: Open
Project: glassfish
Component/s: other
Affects Version/s: 9.0peur1
Fix Version/s: not determined

Type: Bug Priority: Minor
Reporter: robertdw Assignee: pn107121
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: Linux
Platform: Linux

Attachments: Zip Archive gfContextLoader.zip     Zip Archive gfContextLoader.zip     Zip Archive server.zip    
Issuezilla Id: 1,358
Status Whiteboard:



We can not lookup an EJB ref inside of a ServletContextListener. This works
under 9.0pe (b48), but does not work under 9.0peUR1 (b14), so it's a regression.

Attempting to do so results in a stack trace like this:
Caused by: javax.naming.NameNotFoundException: No object bound for
java:comp/env/ejb/Greeter [Root exception is java.lang.NullPointerException]
at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:307)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
... 65 more
Caused by: java.lang.NullPointerException
at com.sun.ejb.EJBUtils.resolveEjbRefObject(EJBUtils.java:283)
... 67 more

Sample code attached.

Comment by robertdw [ 22/Oct/06 ]

Created an attachment (id=538)
Sample code showing bug - bug shows up on deploy and restart

Comment by robertdw [ 22/Oct/06 ]

Created an attachment (id=539)
Log file showing the exception.

Comment by robertdw [ 22/Oct/06 ]

As a side note, this was found in our main application when trying to use Spring
and WebWork in conjuction with EJBs - Spring gets configured via a
ServletContextListener. As stated, this was working in v1-b48 and is not in

Comment by robertdw [ 22/Oct/06 ]

Also occurs in v2-m2

Comment by jluehe [ 23/Oct/06 ]

I was able to reproduce the exception using 9.0peUR1 (b14), but only during a
restart, and not during the initial deployment. I see this warning in the

Invalid Deployment Descriptors element gfContextLoader-ejb.jar#GreeterBean value

I am unable to reproduce the exception using v2-m2, though, even though the
above warning message still appears in the server.log.

Assigning to deployment for them to check if the above warning could be in any
way related to the lookup failure.

Comment by Hong Zhang [ 23/Oct/06 ]

I don't find a binary archive attachment. Could you (or Jan) please attach it?

Looking at the source code, seems the warning that Jan observed:

Invalid Deployment Descriptors element gfContextLoader-ejb.jar#GreeterBean value

is from following element <ejb-local-ref>:


The ejb-ref-type here should be "Session" to match with the referenced ejb
declared in ejb-jar.xml. However, this should be not the cause for the problem.
In the deployment code, after we print such warning, we will use the type of the
referenced ejb to reset the ejb-ref-type in the ejb-ref element.

Jan, if you have the binary archive, you would verify it.

Comment by jluehe [ 23/Oct/06 ]

Hi Hong, you can build the EAR yourself by downloading the attached
gfContextLoader.zip, unzipping it, and running "ant". And you're right about the
warning: I see it getting logged even for those GlassFish versions on which no
exception is thrown during restart, so it must be harmless, but I thought I'd
point it out anyways.

Comment by Hong Zhang [ 23/Oct/06 ]

Thanks, Jan. I build the archive myself now (doh!) and I saw the same thing as
you: I couldn't reproduce it with v2 latest build (whether it's for deployment
or restart). And I could reproduce the exception for restart (but not
deployment) for 9.0 ur1 b14.

Since this happens only for restart and not deployment, do you want to take over
from here?

Comment by robertdw [ 23/Oct/06 ]

Created an attachment (id=542)
Updated example - corrected ejb-ref.

Comment by robertdw [ 23/Oct/06 ]

One workaround is to disable the quickstart. I'm sure you guys know how to do
this, but for other people reading this bug report: you add this JVM option:

Comment by Hong Zhang [ 24/Oct/06 ]

If disabling quick start would make this work, is this issue also a duplicate
issue of 542?

Comment by Hong Zhang [ 24/Oct/06 ]

I just verified turning off quickstart in 9.0ur1 b14 indeed fixed the problem.

This seems a different issue than 542 since that problem is fixed in 9.0ur1 b7
and this problem is still in 9.0ur1 b14. Although everything seems ok in 9.1.

Assign to Binod see what he wants to do here.

Comment by binod [ 17/Jan/07 ]

In any case, in AS 9.1, this is not reproduceable. The quickstartup related
changes for issue 542 is not applicable any more in 9.1. That has been resolved
by changing the startup sequence to start the webcontainer by default and not

Thus, this issue is not applicable for 9.1 any more. Perhaps sustaining need to
backport the webcontainer startup changes to one of the 9.0 patch releases. I
will change th target release to 9.0 for now.

Comment by binod [ 17/Jan/07 ]

Marking the status white board as as91-na.

Comment by binod [ 28/Feb/07 ]

Transfering to Piali to fix this in 9.0 release.

Comment by basler [ 07/Nov/07 ]

Not reproducible in 9.1

Comment by sanandal [ 11/Jan/09 ]

"Reclassifying as P4 because this issue is not deemed "must fix" for this v2.1
release whose primary release driver is SailFin.
This issue will be scrubbed after this release and will be given the right
priority for the next release."

Comment by Tom Mueller [ 06/Mar/12 ]

Bulk update to change fix version to "not determined" for all issues still open but with a fix version for a released version.

Generated at Sun Oct 23 06:09:14 UTC 2016 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.