Uploaded image for project: 'WildFly'
  1. WildFly
  2. WFLY-12274

EJB Bean with mappedName is not binding

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 23.0.0.Beta1, 23.0.0.Final
    • 16.0.0.Final, 17.0.0.Beta1, 17.0.1.Final
    • EJB
    • None
    • Hide

      Deploy mapped-name.jar

      Show
      Deploy mapped-name.jar
    • Hide

      Add @Resources to the EJB Bean to have it bind the expected location of the @EJB(mappedName=...)

      @Resources( {
          @Resource(name="java:/MappedHelloBean", lookup="java:global/mapped-name/HelloBean!com.jboss.examples.ejb.Hello"),
      })
      @Stateless(name="HelloBean", mappedName="MappedHelloBean")
      @Remote(Hello.class)
      public class HelloBean implements Hello {
      

      Or use @Stateless(name=...) and @EJB(name=...)
      Or use @EJB(lookup=... and one the portable JNDI bindings which are defined by EE6+ Or use @Resources on the EJB to create a custom JNDI binding and use @EJB(lookup or @EJB(mappedName=... to lookup the custom binding.

      Note as mappedName is not portable, it is recommended to use name or use lookup and one of the EE6+ portable JNDI bindings.

      Show
      Add @Resources to the EJB Bean to have it bind the expected location of the @EJB(mappedName=...) @Resources( { @Resource(name= "java:/MappedHelloBean" , lookup= "java:global/mapped-name/HelloBean!com.jboss.examples.ejb.Hello" ), }) @Stateless(name= "HelloBean" , mappedName= "MappedHelloBean" ) @Remote(Hello.class) public class HelloBean implements Hello { Or use @Stateless(name=...) and @EJB(name=...) Or use @EJB(lookup=... and one the portable JNDI bindings which are defined by EE6+ Or use @Resources on the EJB to create a custom JNDI binding and use @EJB(lookup or @EJB(mappedName=... to lookup the custom binding. Note as mappedName is not portable, it is recommended to use name or use lookup and one of the EE6+ portable JNDI bindings.

    Description

      EJB Bean with mappedName is not binding , the mappedName is vendor specific, it is not portable, however @EJB(mappedName=...) is expecting a global JNDI path, but @Stateless(mappedName=...) does not appear to be binding anything.

      @Stateless(name="HelloBean", mappedName="MappedHelloBean")
      public class HelloBean implements Hello {
      ...
      
      @Startup
      @Singleton
      public class TestSingleton {
        @EJB(mappedName="MappedHelloBean")
        private Hello ejb;
      ...
      

      So the @EJB causes the TestSingleton to fail.

      22:12:55,637 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 72) MSC000001: Failed to start service jboss.deployment.unit."mapped-name.jar".component.TestSingleton.START: org.jboss.msc.service.StartException in service jboss.deployment.unit."mapped-name.jar".component.TestSingleton.START: java.lang.IllegalStateException: WFLYEE0042: Failed to construct component instance
      ...
      Caused by: javax.ejb.EJBException: java.lang.RuntimeException: WFLYNAM0059: Resource lookup for injection failed: env/com.jboss.examples.ejb.TestSingleton/ejb
      ...
      Caused by: java.lang.RuntimeException: WFLYNAM0059: Resource lookup for injection failed: env/com.jboss.examples.ejb.TestSingleton/ejb
      ...
      Caused by: javax.naming.NamingException: WFLYNAM0062: Failed to lookup env/com.jboss.examples.ejb.TestSingleton/ejb [Root exception is java.lang.RuntimeException: javax.naming.NameNotFoundException: MappedHelloBean -- service jboss.naming.context.java.MappedHelloBean]
      ...
      Caused by: java.lang.RuntimeException: javax.naming.NameNotFoundException: MappedHelloBean -- service jboss.naming.context.java.MappedHelloBean
      ...
      Caused by: javax.naming.NameNotFoundException: MappedHelloBean -- service jboss.naming.context.java.MappedHelloBean
      ...
      

      [1] https://docs.oracle.com/javaee/6/api/javax/ejb/EJB.html#mappedName()

      Attachments

        Issue Links

          Activity

            People

              cfang@redhat.com Cheng Fang
              cfang@redhat.com Cheng Fang
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: