1 Reply Latest reply on Jun 9, 2011 3:07 AM by jaikiran

    Invalid injection via ejb-jar.xml in war

    teliatko

      I have a simple WAR application which uses ejb-jar.xml to specify exact injection of EJB.

      Beginning of my web.xml looks like:

       

      {code}

      <?xml version="1.0" encoding="UTF-8"?>

      <web-app version="3.0"

          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/web-app_3_0.xsd">{code}

       

       

      I am injecting via @EJB annotation SpecialHelloService into HelloClient:

       

      {code}

      @Stateless

      public class SpecialHelloService implements HelloService {

       

       

          @Inject

          @Category("hello")

          private Logger log;

       

       

          @Override

          public void sayHello() {

              log.info("Hello from " + this.getClass().getSimpleName());

          }

      }

       

      @Stateless

      public class HelloClient implements Client {

       

       

          @EJB

          private HelloService service;

       

       

          public void sayHello() {

              service.sayHello();

          }

       

      }

      {code}

       

      but I have also alternative implementation of interface HelloService:

       

      {code}

      @Stateless

      public class DefaultHelloService implements HelloService {

       

       

          @Inject

          @Category("hello")

          private Logger log;

       

       

          @Override

          public void sayHello() {

              log.info("Hello from " + this.getClass().getSimpleName());

          }

      }

      {code}

       

      My ejb-jar.xml located in WEB-INF directory looks like:

       

      {code}

      <?xml version="1.0" encoding="UTF-8"?>

      <ejb-jar 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/ejb-jar_3_1.xsd"

          version="3.1">

       

          <enterprise-beans>

              <session>

                  <ejb-name>HelloClient</ejb-name>

                  <ejb-local-ref>

                      <ejb-ref-name>eu.hello.HelloClient/service</ejb-ref-name>

                      <local>eu.hello.HelloService</local>

                      <ejb-link>SpecialHelloService</ejb-link>

                  </ejb-local-ref>

              </session>

          </enterprise-beans>

       

      </ejb-jar>

      {code}

       

      After starting the server I get en error:

       

      {code}

      DEPLOYMENTS IN ERROR:

        Deployment "vfs:///usr/local/jboss-6.0.0.Final/server/default/deploy/ch2-core.war" is in error due to the following reason(s): java.lang.RuntimeException:

                Specified reference [EJB Reference: beanInterface 'eu.hello.HelloService', beanName 'null', mappedName 'null', lookupName 'null', owning unit 'ComponentDeploymentContext@1425153876{org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData.HelloClient}'] was matched by more than one EJB: [org.jboss.metadata.ejb.jboss.JBossSessionBean31MetaData@a125ae44{DefaultHelloService}, org.jboss.metadata.ejb.jboss.JBossSessionBean31MetaData@33f724bc{SpecialHelloService}].  Specify beanName explciitly or ensure beanInterface is unique.

       

              at org.jboss.deployers.plugins.deployers.DeployersImpl.checkComplete(DeployersImpl.java:1228) [:2.2.0.GA]

              at org.jboss.deployers.plugins.main.MainDeployerImpl.checkComplete(MainDeployerImpl.java:905) [:2.2.0.GA]

              at org.jboss.system.server.profileservice.deployers.MainDeployerPlugin.checkComplete(MainDeployerPlugin.java:87) [:6.0.0.Final]

              at org.jboss.profileservice.deployment.ProfileDeployerPluginRegistry.checkAllComplete(ProfileDeployerPluginRegistry.java:107) [:0.2.2]

              at org.jboss.system.server.profileservice.bootstrap.BasicProfileServiceBootstrap.start(BasicProfileServiceBootstrap.java:135) [:6.0.0.Final]

              at org.jboss.system.server.profileservice.bootstrap.BasicProfileServiceBootstrap.start(BasicProfileServiceBootstrap.java:56) [:6.0.0.Final]

              at org.jboss.bootstrap.impl.base.server.AbstractServer.startBootstraps(AbstractServer.java:827) [jboss-bootstrap-impl-base.jar:2.1.0-alpha-5]

              at org.jboss.bootstrap.impl.base.server.AbstractServer$StartServerTask.run(AbstractServer.java:417) [jboss-bootstrap-impl-base.jar:2.1.0-alpha-5]

              at java.lang.Thread.run(Thread.java:680) [:1.6.0_24]

       

      {code}

       

      It looks like ejb-jar.xml is not taken into consideration, but when I create error in it (e.g. misspelling class name) I get error that the bean does not exist. What can be a problem?

       

      I'm running JBoss AS 6.0.0.Final. Thanks in advance for any help.