Inject an EJB into JAX-RS (RESTful service)

I am not sure this is supposed to work. So either: Option 1: Use the injection provider SPI Implement a provider that will do the lookup and inject the EJB. See: @EJB injection. Example for com.sun.jersey:jersey-server:1.17 : import com.sun.jersey.core.spi.component.ComponentContext; import com.sun.jersey.core.spi.component.ComponentScope; import com.sun.jersey.spi.inject.Injectable; import com.sun.jersey.spi.inject.InjectableProvider; import javax.ejb.EJB; import javax.naming.Context; import javax.naming.InitialContext; import javax.ws.rs.ext.Provider; import java.lang.reflect.Type; … Read more

EJB 3.1 @LocalBean vs no annotation

The rules are (from memory): Bean has a @LocalBean annotation -> bean has a no-interface view Bean has a @Local annotation -> bean has a local view Bean has a @Remote annotation -> bean has a remote view Bean has no view annotations, but directly implements an interface which has a @Local annotation -> bean … Read more

When to use Stateful session bean over Stateless session bean?

First, you have to understand how the beans are created and handled on the server. For stateless session beans the server can maintain a variable amount of instances in a pool. Each time a client requests such a stateless bean (e.g. through a method) a random instance is chosen to serve that request. That means … Read more

Stateless and Stateful Enterprise Java Beans

Stateless Session Beans (SLSB) are not tied to one client and there is no guarantee for one client to get the same instance with each method invocation (some containers may create and destroy beans with each method invocation session, this is an implementation-specific decision, but instances are typically pooled – and I don’t mention clustered … Read more

How do CDI and EJB compare? interact?

It is currently indeed a bit confusing as there are now multiple component models in Java EE. They are CDI, EJB3 and JSF Managed Beans. CDI is the new kid on the block. CDI beans feature dependency injection, scoping and an event bus. CDI beans are the most flexible with respect to injection and scoping. … Read more

Where to use EJB 3.1 and CDI?

Yes, you can freely mix both CDI and EJB and achieve some great results. It sounds like you are using @WebService and @Schedule, which are good reasons for adding EJB to the mix. There’s a lot of confusion out there, so here is some general information on EJB and CDI as they relate to each … Read more