users@glassfish.java.net

Re: _at_PersistenceContext ignored in library jar classes?

From: Laird Nelson <ljnelson_at_gmail.com>
Date: Tue, 28 Aug 2012 11:32:57 -0700

On Tue, Aug 28, 2012 at 10:48 AM, <forums_at_java.net> wrote:

> Could not find anything on this in the jee, ejb, webbeans or jpa
> specification. The Weld documentation [1] says: "All managed beans may take
> advantage of Java EE component environment injection using @Resource, @EJB,
> @PersistenceContext, @PeristenceUnit and @WebServiceRef."
>

I stand corrected; you are quite right. I've held this misconception for
quite a while. Thanks.

As a (gross) workaround, have you tried annotating your library jar with
@ManagedBean? I know this is a horrible-sounding idea, but it was the only
way we could get certain kinds of injection to work with JAX-RS and
GlassFish (we had library jars in an ear file's lib directory and an empty
JAX-RS application deployed as a .war; injection wouldn't work on the
library jars until they were annotated with @ManagedBean, and then at least
we could use @EJB injection inside them).

Best,
Laird

-- 
http://about.me/lairdnelson