[jboss-user] JSF/CDI Managed Bean injecting remote EJB
fernando at lozano.eti.br
fernando at lozano.eti.br
Wed Oct 26 17:02:40 EDT 2011
Hi there,
I'm trying to make a JSF app call a remote EJB. This EJB is in the same
JBoss AS 6.1 instance but was deployed as a standalone EJB-JAR. I wish I
could use @Inject or @EJB to inject the remote EJB proxy into the managed
bean, but it isn't working.
Here's the remote interface
package exemplo;
@Remote
public interface ClienteDAO
{
List listaCidades();
}
And the EJB
package exemplo;
@Stateless
public class ClienteEJB implements ClienteDAO
{
// no other annotations
You see, plain defaults. I can see from jmx-console my EJB is deployed and
bound to ClienteEJB/remote on the global JNDI namespace. JBoss logs also
show everything is fine when deploying the EJB-JAR file:
18:57:16,905 INFO
[org.jboss.ejb3.proxy.impl.jndiregistrar.JndiSessionRegistrarBase] Binding
the following Entries in Global JNDI:
ClienteEJB/remote - EJB3.x Default Remote Business Interface
ClienteEJB/remote-exemplo.ClienteDAO - EJB3.x Remote Business Interface
Now here's the managed bean:
package exemplo;
@Named("clientes")
@RequestScoped
public class ConsultaClientes implements java.io.Serializable {
@EJB
private ClienteDAO dao;
// no other annotations
When I deploy the WAR containing this, JBoss logs show the error:
18:51:39,619 ERROR
[org.jboss.kernel.plugins.dependency.AbstractKernelController] Error
installing to Real:
name=vfs:///home/lozano/cursos/labs-jbossas6-adm/jboss-6.1.0.Final/server/default/deploy/clientes.war
state=PreReal mode=Manual requiredState=Real:
org.jboss.deployers.spi.DeploymentException: Error during deploy:
vfs:///home/lozano/cursos/labs-jbossas6-adm/jboss-6.1.0.Final/server/default/deploy/clientes.war
..
Caused by: java.lang.RuntimeException: Could not resolve @EJB reference:
[EJB Reference: beanInterface 'exemplo.ClienteDAO', beanName 'null',
mappedName 'null', lookupName 'null', owning unit
'AbstractVFSDeploymentContext at 1040164109{vfs:///home/lozano/cursos/labs-jbossas6-adm/jboss-6.1.0.Final/server/default/deploy/clientes.war}']
for environment entry: env/exemplo.ConsultaClientes/dao in unit
AbstractVFSDeploymentContext at 1040164109{vfs:///home/lozano/cursos/labs-jbossas6-adm/jboss-6.1.0.Final/server/default/deploy/clientes.war}
I tried adding attribute mappedName to the @EJB annotation. But jboss logs
show:
18:53:46,011 WARN
[org.jboss.deployment.MappedReferenceMetaDataResolverDeployer] Unresolved
references exist in
JBossWebMetaData:[#web-app:AnnotatedEJBReferenceMetaData{name=exemplo.ConsultaClientes/dao,ejb-ref-type=null,link=null,ignore-dependecy=false,mapped/jndi-name=ClienteEJB/remote,resolved-jndi-name=null,beanInterface=interface
exemplo.ClienteDAO}]
18:53:46,097 INFO
[org.jboss.web.tomcat.service.deployers.TomcatDeployment] deploy,
ctxPath=/clientes
And when I try to run the web app I get the error:
javax.servlet.ServletException: Could not resolve reference [EJB
Reference: beanInterface 'exemplo.ClienteDAO', beanName '', mappedName
'null'] in
AbstractVFSDeploymentContext at 1131335075{vfs:///home/lozano/cursos/labs-jbossas6-adm/jboss-6.1.0.Final/server/default/deploy/clientes.war}
javax.faces.webapp.FacesServlet.service(FacesServlet.java:321)
org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:67)
root cause
org.jboss.ejb3.ejbref.resolver.spi.UnresolvableReferenceException: Could
not resolve reference [EJB Reference: beanInterface 'exemplo.ClienteDAO',
beanName '', mappedName 'null'] in
AbstractVFSDeploymentContext at 1131335075{vfs:///home/lozano/cursos/labs-jbossas6-adm/jboss-6.1.0.Final/server/default/deploy/clientes.war}
org.jboss.ejb3.ejbref.resolver.ejb30.impl.ScopedEJBReferenceResolver.resolveEjb(ScopedEJBReferenceResolver.java:80)
I also tried providing a jboss-web.xml file:
env/exemplo.ConsultaClientes/dao
ClienteEJB/remote
But it also doesn't work. I get the error on jboss logs:
18:58:48,735 ERROR
[org.jboss.kernel.plugins.dependency.AbstractKernelController] Error
installing to Real:
name=vfs:///home/lozano/cursos/labs-jbossas6-adm/jboss-6.1.0.Final/server/default/deploy/clientes.war
state=PreReal mode=Manual requiredState=Real:
org.jboss.deployers.spi.DeploymentException: Error during deploy:
vfs:///home/lozano/cursos/labs-jbossas6-adm/jboss-6.1.0.Final/server/default/deploy/clientes.war
..
Caused by: java.lang.RuntimeException: Could not resolve @EJB reference:
[EJB Reference: beanInterface 'exemplo.ClienteDAO', beanName 'null',
mappedName 'null', lookupName 'null', owning unit
'AbstractVFSDeploymentContext at 405139541{vfs:///home/lozano/cursos/labs-jbossas6-adm/jboss-6.1.0.Final/server/default/deploy/clientes.war}']
for environment entry: env/exemplo.ConsultaClientes/dao in unit
AbstractVFSDeploymentContext at 405139541{vfs:///home/lozano/cursos/labs-jbossas6-adm/jboss-6.1.0.Final/server/default/deploy/clientes.war}
I tried other @EJB attributes but nothing seem to work. The only way I
found to make this work so far was explicit looking for my EJB:
@Named("clientes")
@RequestScoped
public class ConsultaClientes implements java.io.Serializable {
private ClienteDAO dao;
@PostConstruct
public void inicializa() throws NamingException {
InitialContext ctx = new InitialContext();
dao = (ClienteDAO)ctx.lookup("ClienteEJB/remote");
}
So, is there a way to make @EJB work to inject a Remote EJB (from the same
JBoss AS 6.1 instance) deployed as a stand-aline EJB-JAR into a Managed
Bean inside it's own WAR, without packaging both as part of the same EAR?
[]s, Fernando Lozano
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20111026/ee1d7dfb/attachment-0001.html
More information about the jboss-user
mailing list