6 Replies Latest reply on Jul 24, 2011 4:23 AM by chris81t

    Access to EJB ( JBoss AS 7 )

    chris81t

      Hi @all,

       

      I hope you can help me. I'm actually new to JBoss AS.

       

      For the first test I have written a simple HelloJBoss application:

       

      - HelloJBossAS7 (eclipse ear project contains the two following projects)

      - HelloJBossEJB

           contains:

       

      ISimpleEJB.java

      package de.example.ejb;
      
      
      import javax.ejb.Local;
      
      
      @Local
      public interface ISimpleEJB {
                int add(int a, int b) throws Exception;
      }
      
      

         

      SimpleEJB.java

      package de.example.ejb;
      
      
      import javax.ejb.Stateless;
      
      
      @Stateless
      public class SimpleEJB implements ISimpleEJB {
      
      
                @Override
                public int add(int a, int b) throws Exception {
                          return a + b;
                }
      
      
      }
      
      

       

      - HelloJBossJSF (2.0)

           contains

       

      Content.java

      package de.example.beans;
      
      
      import java.io.Serializable;
      
      
      import javax.ejb.EJB;
      import javax.faces.bean.ManagedBean;
      import javax.faces.bean.SessionScoped;
      
      
      import de.example.ejb.ISimpleEJB;
      
      
      @ManagedBean
      @SessionScoped
      public class Content implements Serializable {
      
      
                private static final long serialVersionUID = 5526381952953438091L;
      
      
                private String title = "Hello JBoss AS 7 :-)";
        
                @EJB(beanName = "SimpleEJB")
                private ISimpleEJB ejb;
        
                public String getTitle() {
                          return title;
                }
      
      
                public void setTitle(String title) {
                          this.title = title;
                }
        
                public int getVal() {
                          try {
                                    return ejb.add(2, 4); 
                          }
                          catch (Exception e) {
                                    return -1; 
                          }
                }
      }
      
      

       

      content.xhtml

       

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml"
            xmlns:h="http://java.sun.com/jsf/html"
            xmlns:f="http://java.sun.com/jsf/core"
            xmlns:ui="http://java.sun.com/jsf/facelets">
                <f:view contentType="text/html"/>
      
      
                <h:head>
                    <title>Hello JBoss AS 7</title>
                </h:head>
        
                <h:body> 
                           <h:outputText value="Title: #{content.title}"/>
                          <br/>
                          <br/>
                          <h:outputText value="Content: #{content.val}"/>
                </h:body>
      
      
      </html>
      
      

       

      web.xml

      jboss-web.xml

      faces-config.xml

       

       

      If I delete the ejb-member "ejb" in the Content class, I can deploy the EAR to the jboss and the jsf app work's fine. But if I use the "ejb" member, I will get the following deployment error:

       

      23:54:13,542 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-5) MSC00001: Failed to start service jboss.deployment.subunit."HelloJBossAS7.ear"."HelloJBossJSF.war".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.subunit."HelloJBossAS7.ear"."HelloJBossJSF.war".INSTALL: Failed to process phase INSTALL of subdeployment "HelloJBossJSF.war" of deployment "HelloJBossAS7.ear"

                at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:121)

                at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1765)

                at org.jboss.msc.service.ServiceControllerImpl$ClearTCCLTask.run(ServiceControllerImpl.java:2291)

                at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_26]

                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_26]

                at java.lang.Thread.run(Thread.java:662) [:1.6.0_26]

      Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: No component found for type 'de.example.ejb.ISimpleEJB' with name SimpleEJB

                at org.jboss.as.ejb3.deployment.processors.EjbInjectionSource.getResourceValue(EjbInjectionSource.java:68)

                at org.jboss.as.ee.component.ModuleJndiBindingProcessor.addJndiBinding(ModuleJndiBindingProcessor.java:187)

                at org.jboss.as.ee.component.ModuleJndiBindingProcessor$1.handle(ModuleJndiBindingProcessor.java:154)

                at org.jboss.as.ee.component.ClassDescriptionTraversal.run(ClassDescriptionTraversal.java:52)

                at org.jboss.as.ee.component.ModuleJndiBindingProcessor.processClassConfigurations(ModuleJndiBindingProcessor.java:125)

                at org.jboss.as.ee.component.ModuleJndiBindingProcessor.deploy(ModuleJndiBindingProcessor.java:118)

                at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:115)

                ... 5 more

       

       

      23:54:13,748 INFO  [org.jboss.as.server.controller] (DeploymentScanner-threads - 2) Deployment of "HelloJBossAS7.ear" was rolled back with failure message {"Failed services" => {"jboss.deployment.subunit.\"HelloJBossAS7.ear\".\"HelloJBossJSF.war\".INSTALL" => "org.jboss.msc.service.StartException in service jboss.deployment.subunit.\"HelloJBossAS7.ear\".\"HelloJBossJSF.war\".INSTALL: Failed to process phase INSTALL of subdeployment \"HelloJBossJSF.war\" of deployment \"HelloJBossAS7.ear\""},"Services with missing/unavailable dependencies" => ["jboss.naming.context.java.comp.HelloJBossAS7.HelloJBossJSF.HelloJBossJSF.ValidatorFactory missing [ jboss.naming.context.java.module.HelloJBossAS7.HelloJBossJSF ]","jboss.naming.context.java.comp.HelloJBossAS7.HelloJBossJSF.HelloJBossJSF.Validator missing [ jboss.naming.context.java.module.HelloJBossAS7.HelloJBossJSF ]"]}

      23:54:13,755 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-12) Stopped deployment HelloJBossJSF.war in 7ms

      23:54:13,757 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-15) Stopped deployment HelloJBossAS7.ear in 9ms

      23:54:13,759 ERROR [org.jboss.as.deployment] (DeploymentScanner-threads - 1) {"Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-2" => {"Failed services" => {"jboss.deployment.subunit.\"HelloJBossAS7.ear\".\"HelloJBossJSF.war\".INSTALL" => "org.jboss.msc.service.StartException in service jboss.deployment.subunit.\"HelloJBossAS7.ear\".\"HelloJBossJSF.war\".INSTALL: Failed to process phase INSTALL of subdeployment \"HelloJBossJSF.war\" of deployment \"HelloJBossAS7.ear\""},"Services with missing/unavailable dependencies" => ["jboss.naming.context.java.comp.HelloJBossAS7.HelloJBossJSF.HelloJBossJSF.ValidatorFactory missing [ jboss.naming.context.java.module.HelloJBossAS7.HelloJBossJSF ]","jboss.naming.context.java.comp.HelloJBossAS7.HelloJBossJSF.HelloJBossJSF.Validator missing [ jboss.naming.context.java.module.HelloJBossAS7.HelloJBossJSF ]"]}}}

       

       

       

      Is using the @EJB annotation the wrong way? Should I user instead a ServiceLocator?! I hope, someone can help me and tell me the correct way to use the SimpleEJB.

       

      Who want's to see the whole project's, have a look the the attachment.

       

      Thank you for support!

        • 1. Re: Access to EJB ( JBoss AS 7 )
          chris81t

          I've also tried:

           

          ...

          public class Content implements Serializable {

                      private static final long serialVersionUID = 5526381952953438091L;

                      private String title = "Hello JBoss AS 7 :-)";

           

                    @EJB(lookup="java:app/HelloJBossEJB/SimpleEJB!de.example.ejb.ISimpleEJB")

              private ISimpleEJB ejb;

          ...

           

          ( source: https://docs.jboss.org/author/display/AS7/Developer+Guide#DeveloperGuide-JNDIPortableJNDISyntax )

           

          But it does not work... The lookup name must be correct, while I've also deployed the EJB Project standalone to the JBoss. Then it has told me:

           

          d 1-10) JNDI bindings for session bean named SimpleEJB in deployment unit deployment "HelloJBossEJB.jar" are as follows:

           

           

                  java:global/HelloJBossEJB/SimpleEJB!de.example.ejb.ISimpleEJB

                  java:app/HelloJBossEJB/SimpleEJB!de.example.ejb.ISimpleEJB

                  java:module/SimpleEJB!de.example.ejb.ISimpleEJB

                  java:global/HelloJBossEJB/SimpleEJB

                  java:app/HelloJBossEJB/SimpleEJB

                  java:module/SimpleEJB

           

           

          12:14:26,698 INFO  [org.jboss.as.server.controller] (DeploymentScanner-threads - 2) Deployed "HelloJBossEJB.jar"

           

          I hope, someone can help me?!

           

          Kind regards!

          • 2. Re: Access to EJB ( JBoss AS 7 )
            jaikiran

            Do you have the application binary .ear that you deploy, instead of the attached source?

            • 3. Re: Access to EJB ( JBoss AS 7 )
              jaikiran

              I'm interested in seeing how and where the EJB jar(s) are packaged within the .ear.

              • 4. Re: Access to EJB ( JBoss AS 7 )
                chris81t

                Hi, thank's for your anwer!

                 

                What I have done:

                 

                I'm using Eclipse Indigo with the JBoss Tools 3.3.0 M2

                Then I have created 3 projects:

                1. HelloJBossEJB normal java project

                2. HelloJBossJSF dyn. web project

                3. HelloJBossAS7 eclipse ear project ( set the project references to the another project's )

                 

                Under the "server" page in the eclipse IDE I have created a jboss server entry to my jboss server. There I have added the ear project (hot deployment) and have started the server out of the eclipse IDE.

                 

                Ok, this is the EAR structure:

                 

                • META-INF
                  • MANIFEST.MF
                • lib
                  • HelloJBossEJB.jar
                • HelloJBossJSF.war

                 

                see the attachment for the EAR file.

                 

                For a few minutes I have tried to manually deploy the EAR file without using Eclipse. But it doesn't work too :-(

                 

                 

                the content of the .failed file of the deployment:

                {"Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-2" => {"Services with missing/unavailable dependencies" => ["jboss.deployment.subunit.\"HelloJBossAS7.ear\".\"HelloJBossJSF.war\".jndiDependencyService missing [ jboss.naming.context.java.module.HelloJBossAS7.HelloJBossJSF.\"env/de.example.beans.Content/ejb\" ]","jboss.deployment.subunit.\"HelloJBossAS7.ear\".\"HelloJBossJSF.war\".component.\"managed-bean.de.example.beans.Content\".START missing [ jboss.naming.context.java.module.HelloJBossAS7.HelloJBossJSF.\"env/de.example.beans.Content/ejb\" ]","jboss.naming.context.java.module.HelloJBossAS7.HelloJBossJSF.\"env/de.example.beans.Content/ejb\".jboss.deployment.subunit.\"HelloJBossAS7.ear\".\"HelloJBossJSF.war\".module.HelloJBossAS7.HelloJBossJSF.0 missing [ jboss.naming.context.java.app.HelloJBossAS7.\"HelloJBossEJB/SimpleEJB!de.example.ejb.ISimpleEJB\" ]"]}}}

                 

                What is the jndiDependencyService?

                 

                btw: I have downloaded the final JBoss AS7 release "Everything (NOT Java EE6 Certified)"

                • 5. Re: Access to EJB ( JBoss AS 7 )
                  jaikiran

                  Move the HelloJBossEjb.jar outside of the .ear/lib and place it at the root of the .ear, just like the .war.

                  • 6. Re: Access to EJB ( JBoss AS 7 )
                    chris81t

                    That's it! Thank you

                     

                    Now it work's fine. But why is it so? The /lib folder is a default setting of the eclipse EAR project type.