cdi

Inject EJB into domain object with Java EE 6

How can I inject an EJB into a domain object (an JPA entity) with Java EE 6? ...

Resolution of external (3rd party) beans in weld

I know it is still not quite popular, since the spec was released just a few months ago. I haven't "installed" weld yet, I'm just reading, and by this question I want to make sure I've understood this important point correct: Is resolution of beans that are in 3rd-party jars achieved by declaring them as <alternatives> in your beans.xm...

Differences between Java EE 6 CDI Implementations

I've looked at JBoss' Weld Reference Implementation of JSR-299 Contexts and Dependency Injection, and I wanted to know how others CDI implementations compare to each other. Specifically, I know about Weld, Resin CanDI (by Caucho), and Apache OpenWebBeans. ...

how to instantiate more then one CDI/Weld bean for one class ?

In Spring it was possible to instantiate any class by defining the corresponding bean in xml conf. It was also possible to instantiate more then one bean for the same class with different parameters..... Are the such features in CDI as well, namely is it possible to create different instances of the same class with different initializ...

How to inject a Session Bean into a Message Driven Bean?

I'm reasonably new to JEE, so this might be stupid.. bear with me pls :D I would like to inject a stateless session bean into a message-driven bean. Basically, the MDB gets a JMS message, then uses a session bean to perform the work. The session bean holds the business logic. Here's my Session Bean: @Stateless public class TestBean im...

How to test a DAO with JPA implementation ?

Hi I came from the Spring camp , I don't want to use Spring , and am migrating to JavaEE6 , But I have problem testing DAO + JPA , here is my simplified sample : public interface PersonDao { public Person get(long id); } This is a very basic DAO , because I came from Spring , I believe DAO still has its value , so I decided to add...

Java EE without Application Server

Since EJB 3 we have embeddable EJB containers, JPA implementations can be used without an application server, there is Weld for contexts and dependency injection and so on. Since on many systems is only Tomcat available, I wonder, if Java EE could be used without an application server but with a Servlet container like Tomcat. What woul...

Dependency Injection with @Inject in Weld (JSR-299 RI). How is the corresponding @Produces found?

I have played with the JSR-299 Reference Implementation "Weld" with the purpose of using it in a stand-alone application, and I have had a look at the documentation, and marveled at the magic. My question is how the producer of a given object to be @Inject'ed is found? Either the java compiler produces hints for annotations which is ea...

Google Guice vs. JSR-299 CDI / Weld

Weld, the JSR-299 Contexts and Dependency Injection reference implementation, considers itself as a kind of successor of Spring and Guice. CDI was influenced by a number of existing Java frameworks, including Seam, Guice and Spring. However, CDI has its own, very distinct, character: more typesafe than Seam, more stateful and less X...

Can one suppress the conversation propagation with an `<h:link>`?

I'm using the new JSF2 <h:link> tag, with a nested <f:param> to link to a page using a get request. However, the conversation id (cid) is propagated via the query parambeters of the link to the new page. Can one suppress the conversation propagation with an <h:link>? ie. no cid=# in the url...? ...

Injecting logger, weld

Hi. I am trying to replace standard logger initialization by some injection 1-st. I was trying to use weld weld logging in stateless bean/webservices @Stateless @WebService public class EchoSSL { @Inject private Logger log; public EchoSSL() { } public String echo(String msg) { log.debug("Log test"); ...

EJB injection in Glassfish webapp

I've got an app that is trying to use @EJB annotation to inject remote references to EJBs in my ejb.jar file. I'm getting inconsistent results. In one case, I have a listener in web.xml that gets called and apparently has the EJB injected correctly, since I can see it connecting to the EJB and calling methods on it. In another class (...

How to inject beans from external libs with CDI?

How can I use JSR-299 CDI to inject (not annotated) beans from external libraries? Examples: Interface X and its implementations come from a third party lib. How can I decide which implementation to use? class A { @Inject private X x; } What if I had several classes using the X interface but different implementations? cl...

CDI timeout results in an NPE

Is there a way (in JSF 2) to catch a Conversation timeout and redirect a user to a new page? I'm getting nasty NullPointerExceptions when the conversation times out. I could redirect the user on all NPE's, but that seems like too big a net. ...

Whats the relationship between Spring and javax.enterprise.inject?

I was reading a Wikipedia article about Java EE application servers here: http://en.wikipedia.org/wiki/Java_Platform,_Enterprise_Edition#Java_EE_5_certified It says that 2 APIs that Java App Services implement are: javax.enterprise.inject javax.enterprise.context These both relate to application context and dependency injection JSR-...

CDI/JSF and JAX-RS?

I would like to use RESTful services in a CDI/JSF2 application. I am not very familiar with JAX-RS however I have read that its lifecycle does not play well with CDI/JSF2. Is it possible to incorporate JAX-RS with CDI/JSF2 in a JEE6 stack? If not are there alternatives? thanks ...

How to inject a non-serializable class (like java.util.ResourceBundle) with Weld

I want to create a Producer that makes it possible to inject a java.util.ResourceBundle into any class in order to get localized Strings easily. My ResourceBundle-Producer looks like this: public class ResourceBundleProducer { @Inject public Locale locale; @Inject public FacesContext facesContext; @Produces p...

Where should I declare my CDI resources?

JSR-299 (CDI) introduces the (unfortunately named) concept of a resource: http://docs.jboss.org/weld/reference/1.0.0/en-US/html/resources.html#d0e4373 You can think of a resource in this nomenclature as a bridge between the Java EE 6 brand of dependency injection (@EJB, @Resource, @PersistenceContext and the like) and CDI's brand of dep...

How to cascade dependency resolution w/ CDI (WELD)

I would like to have a central weld container that holds all my services and so on. This container would however be wrapped by a second container which contains local settings. The goal is if a dependency cannot be found in the outer container then I would like to then search the inner container. How can I achieve this? I would prefer t...

Is there an equivalent in CDI(WELD) to build definitions (as done in Guice modules) and then create an Injector ?

I like the way Guice makes it fairly straight forward to manually create your own modules each with their own bindings done in code. CDI on the other hand seems to rely more on magic rather than programmatic access to sest bindings. Am i wrong or how can one achieve the same effect with WELD. Any code sample would be appreciated... CLA...