I was using a mixture of EJB3 and Guice injection following method described here. The sample source code is available here.
- Local EJB : source
- Injected service (by Guice): source
- Guice module : source
- Guice interceptor stuff : source
- Servlet, EJB consumer : source
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.
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.
@Stateless
@Interceptors(value = { GuiceInterceptor.class })
@Local
public class TestSessionBean implements TestSessionBeanLocal {
// Add business logic below. (Right-click in editor and choose
// "Insert Code > Add Business Method"
@Inject
private InjectedService iService;
@Override
public String getHello() {
return "Hello, I'm your test session bean";
}
@Override
public String getMessageFromInjected() {
return iService.helloFromInjected();
}
}
Solution Solution was quite simple, just replace:
//import com.google.inject.Inject; import com.google.inject.Inject;Another remedy was adding empty bean.xml file to META-INF directory.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">

Brak komentarzy:
Prześlij komentarz