0 Replies Latest reply on May 11, 2015 7:12 AM by i.barhoumi

    EJB injection inside a .SAR module error Wildfly

    i.barhoumi

      Hello,

       

      I've an .ear contains EJb modules and SAR module. My EJBs are remote and déployed in my wildfly8.2, they are tested with JUnit and client project ( every thing is alright).

      Now, when i try to invoke my EJB from my SAR module using @EJB i have a dependency error.

       

      Here the jboss-service.xml of my .sar module

       

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

      <server xmlns="urn:jboss:service:7.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

          xsi:schemaLocation="urn:jboss:service:7.0 jboss-service_7_0.xsd">

          <mbean

              code="com.alliancenic.registry.registrycommunicator.RegistryCommunicatorService"

              name="AllianceNic:service=RegistryCommunicator">

              <!-- <depends>jboss:service=Naming</depends>

              <depends>jboss.jca:service=ConnectionFactoryBinding,name=JmsXA

              </depends>

              <attribute name="Frequency">1000</attribute> -->

              <!-- <attribute name="Latency">300000</attribute> -->

          </mbean>

       

      </server>

       

      Here the service hwo call the EJB

       

      package com.alliancenic.registry.registrycommunicator;

       

      import java.util.ArrayList;

      import java.util.HashMap;

      import java.util.List;

      import java.util.Map;

       

      import javax.ejb.EJB;

      import javax.ejb.Singleton;

      import javax.ejb.Startup;

      import javax.inject.Named;

      import javax.naming.InitialContext;

      import javax.naming.NamingException;

       

      import org.jboss.logging.Logger;

       

      import com.alliancenic.objects.RegistryEnum.RootRegistry;

      import com.alliancenic.registrar.facade.ejb.remote.RegistryManagerRemote;

      import com.alliancenic.registrar.persistence.mapping.Registry;

       

      @Named

       

      public class RegistryCommunicatorService implements

              RegistryCommunicatorServiceMBean {

       

          @EJB

          RegistryManagerRemote ManagerRemote;

       

          public RegistryManagerRemote getManagerRemote() {

              return ManagerRemote;

          }

       

          public void setManagerRemote(RegistryManagerRemote managerRemote) {

              ManagerRemote = managerRemote;

          }

       

          private static final String START_STATE_JNDI_KEY = "Services/RegistryCommunicator/RunOnStart";

       

          private static Logger log = Logger

                  .getLogger(RegistryCommunicatorService.class);

       

          private boolean runOnStart;

          private Map<String, PersistServiceTask> communicatorTasks;

          private NoPersistLimitedServiceTask noPersistLimitedTask;

          private NoPersistServiceTask noPersistTask;

       

          public RegistryCommunicatorService() {

              communicatorTasks = new HashMap<String, PersistServiceTask>();

              try {

                  InitialContext context = new InitialContext();

                  runOnStart = Boolean.parseBoolean((String) context

                          .lookup(START_STATE_JNDI_KEY));

                  log.info("**** JNDI RunOnStart Charged on server ****");

              } catch (NamingException e) {

                  // nothing to do, service will not run on startup

                  runOnStart = true;

                  log.info("**** unable to Charge JNDI RunOnStart on server ****");

              }

          }

       

          @Override

          public void start() {

              if (runOnStart) {

                  startRegistryCommunicatorService();

              }

          }

       

          private void startRegistryCommunicatorService() {

              log.info("**** starting EppCommunicator Service ****");

       

              startNoPersistLimitedServiceTask();

       

              startNoPersistServiceTask();

       

              List<Registry> registryList = getRegistryServiceListToStart();

              startPersistServiceTask(registryList);

          }

       

          private void startNoPersistLimitedServiceTask() {

              try {

                  noPersistLimitedTask = new NoPersistLimitedServiceTask();

                  noPersistLimitedTask.startTask();

              } catch (Exception e) {

                  log.error("Error starting NoPersistLimitedServiceTask", e);

              }

          }

       

          private void startNoPersistServiceTask() {

              try {

                  noPersistTask = new NoPersistServiceTask(

                          RootRegistry.CORE.getIndex());

                  noPersistTask.startTask();

              } catch (Exception e) {

                  log.error("Error starting NoPersistServiceTask", e);

              }

          }

       

          private List<Registry> getRegistryServiceListToStart() {

              List<Registry> registryList = new ArrayList<Registry>();

              try {

                  registryList = ManagerRemote.getRegistryListToStart();

              } catch (Exception e) {

                  log.error(

                          "!!!!!!! Unable to getRegistryListToStart for EppCommunicator !!!!!!",

                          e);

              }

              return registryList;

          }

       

          private void startPersistServiceTask(List<Registry> registryList) {

              for (Registry registry : registryList) {

                  try {

                      if (registry.isService()) {

                          log.debug("---- starting registry " + registry.getName());

                          String registryName = registry.getName().toLowerCase();

                          PersistServiceTask task = communicatorTasks

                                  .get(registryName);

                          if (task == null

                                  || task.getState() == Thread.State.TERMINATED) {

                              task = new PersistServiceTask(registryName);

                              communicatorTasks.put(registryName, task);

                          }

       

                          if (task.isRunning())

                              log.warn("communicator for '" + registry

                                      + "' is already running");

                          else

                              task.startTask();

                      }

       

                  } catch (Exception ex) {

                      log.error("Error starting service " + registry.getName(), ex);

                  }

              }

          }

       

          @Override

          public void stop() {

              log.info("Stopping Communicator Service");

              List<String> tasksToRemove = new ArrayList<String>();

       

              for (String registry : communicatorTasks.keySet()) {

                  PersistServiceTask task = communicatorTasks.get(registry);

                  try {

                      log.debug("Stopping '" + registry + "'");

                      tasksToRemove.add(registry);

                      task.stopTask();

                  } catch (Exception ex) {

                      log.error("Unable to stop '" + registry + "' service task", ex);

                  }

              }

       

              for (String registry : tasksToRemove) {

                  try {

                      log.info("Waiting for '" + registry

                              + "' service task to stop...");

                      communicatorTasks.get(registry).join();

                      log.info("'" + registry + "' service task stopped");

                  } catch (Exception ex) {

                      // nothing to do

                      log.error("Unable to join task for '" + registry + "'", ex);

                  }

                  communicatorTasks.remove(registry);

              }

              if (communicatorTasks.size() != 0) {

                  log.error("communicatorTasks contains " + communicatorTasks.size()

                          + " tasks");

              }

       

              noPersistLimitedTask.stopTask();

              noPersistTask.stopTask();

       

              log.info("Communicator Service stopped");

          }

      }

       

      The error log is like this

      12:00:28,383 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) JBAS014613: Operation ("deploy") failed - address: ([("deployment" => "AllianceNicEAR.ear")]) - failure description: {"JBAS014771: Services with missing/unavailable dependencies" => ["jboss.deployment.subunit.\"AllianceNicEAR.ear\".\"AllianceNicEppCommunicatorSAR-0.0.1-SNAPSHOT.sar\".component.AllianceNic:service=RegistryCommunicator.START is missing [jboss.naming.context.java.module.AllianceNicEAR.\"AllianceNicEppCommunicatorSAR-0.0.1-SNAPSHOT.sar\".env.\"com.alliancenic.registry.registrycommunicator.RegistryCommunicatorService\".ManagerRemote]"]}