users@glassfish.java.net

Re: CDI broken between EJB and JPA modules

From: <glassfish_at_javadesktop.org>
Date: Wed, 07 Apr 2010 21:38:03 PDT

http://www.theserverside.com/news/1373391/Dependency-Injection-in-Java-EE-6-Part-1

"How the Pieces Fit Together

...

Managed beans are a key concept introduced in Java EE 6 to solve some of the limitations we talked about in the previous section with Java EE 5 style resource injection. A managed bean is just a bare Java object in a Java EE environment. Other than Java object semantics, it has a well-defined create/destroy life-cycle that you can get callbacks for via the @PostConstruct and @PreDestroy annotations. [b]Managed beans can be explicitly denoted via the @ManagedBean annotation, but this is not always needed, especially with CDI. From a CDI perspective, this means that almost any Java object can be treated as managed beans and so can be full participants in dependency injection.[/b]"

Did I misunderstand the above? I thought that was the whole magic of CDI, that it allows dependency injection into POJOs by inspecting the annotations they contain, whether or not those POJOs were annotated with @ManagedBean at the top.

Further down in that same article, under the section "Dependency Injection Basics", the author uses a Dao example, with an interface and an implementation class, and the latter has the @PersistenceContext injected. The Dao is a POJO, and has no @ManagedBean annotation. So she basically does exactly what I'm trying to do, except for some reason it's not working for me.


As for the attachments... Are you getting these posts via a mailing list? Even so, not sure why the attachments wouldn't have made it. In any case, you can see them here:

http://forums.java.net/jive/thread.jspa?threadID=78223

-Dan
[Message sent by forum member 'theodan']

http://forums.java.net/jive/thread.jspa?messageID=395830