Blog do projektu Open Source JavaHotel

poniedziałek, 24 czerwca 2013

Glassfish 4.0 and Guice

I was using a mixture of EJB3 and Guice injection following method described here. The sample source code is available here.
Glassfish 3.1
It works without problem with Glassfish 3.1 giving the desired result
Glassfish 4.0
But deployment failed when I tried the same code to push into Glassfish 4.0.
deploy?DEFAULT=/home/hotel/NetBeansProjects/Container/TestApp/dist/gfdeploy/TestApp&name=TestApp&force=true failed on GlassFish Server (1) 
 Error occurred during deployment: Exception while loading the app : CDI deployment failure:WELD-001408 Unsatisfied dependencies for type [InjectedService] with qualifiers [@Default] at injection point [[BackedAnnotatedField] @Inject private com.test.myejb.TestSessionBean.iService]. Please see server.log for more details.

It looks that CDI implementation in Glassfish 4.0 is trying to resolve @Inject annotation on its own just ignoring the fact that it should be handled by @Interceptors annotation.

@Interceptors(value = { GuiceInterceptor.class })
public class TestSessionBean implements TestSessionBeanLocal {

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method"
    private InjectedService iService;
    public String getHello() {
        return "Hello, I'm your test session bean";

    public String getMessageFromInjected() {
        return iService.helloFromInjected();

Solution was quite simple, just replace:
Another remedy was adding empty bean.xml file to META-INF directory.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""

Brak komentarzy:

Prześlij komentarz