6 Replies Latest reply on Jul 19, 2006 2:10 PM by vulee

    Dependency Injection of an Message Driven POJO into a SSB

    andy.miller

      I have been trying to inject a dependency in a stateless session bean for a message driven POJO, and it cannot resolve the name just using the interface. This is the message from the log on deployment:

      For EJB InventoryManagerBean could not find jndi binding based on interface only for @EJB(services.ejb.ReplenishmentProcessor) not used by any EJBs

      I have the following in my stateless session bean:

      @EJB
      private ReplenishmentProcessor replenish;

      My message driven POJO is as follows:

      package services.ejb;
      
      import java.math.BigDecimal;
      
      import javax.annotation.EJB;
      import javax.ejb.ActivationConfigProperty;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;
      
      import org.apache.commons.logging.Log;
      import org.apache.commons.logging.LogFactory;
      import org.jboss.annotation.ejb.Consumer;
      
      import services.entities.DistributionCenter;
      import services.entities.ProductDemand;
      import services.entities.ProductDemandPK;
      import services.entities.PurchaseOrder;
      
      @Consumer(activationConfig = {
       @ActivationConfigProperty(propertyName="destinationType"
       , propertyValue="javax.jms.Queue"),
       @ActivationConfigProperty(propertyName="destination"
       , propertyValue="queue/replenish")
       })
      public class ReplenishmentProcessorBean implements ReplenishmentProcessor {
      
       private static Log log;
      
       @PersistenceContext (unitName="services")
       protected EntityManager entityManager;
      
       @EJB
       private SupplierManager supplierManager;
      
       public ReplenishmentProcessorBean() {
      
       }
      
       public void replenishInventory(long productId, long distributionCenterId) {
      
       log = LogFactory.getLog(ReplenishmentProcessorBean.class);
      
       ProductDemand demand = null;
       ProductDemandPK productDemandPK = new ProductDemandPK();
      
       productDemandPK.setProductId(productId);
       productDemandPK.setDistributionCenterId(distributionCenterId);
      
       demand = entityManager.find(ProductDemand.class, productDemandPK);
      
       if (demand == null) {
       log.error("There is no ProductDemand for productId: " + productId);
       return;
       }
      
       PurchaseOrder po = new PurchaseOrder();
      
       po.setProductId(productId);
       po.setDistributionCenterId(distributionCenterId);
      
       DistributionCenter distributionCenter = null;
      
       distributionCenter = (DistributionCenter) entityManager.find(DistributionCenter.class
       , Long.valueOf(distributionCenterId));
      
       if (distributionCenter == null) {
       log.error("Missing DistributionCenter for distributionCenterId: " + distributionCenterId);
       return;
       }
      
       po.setAddressLine1(distributionCenter.getAddressLine1());
       po.setAddressLine2(distributionCenter.getAddressLine2());
       po.setCity(distributionCenter.getCity());
       po.setState(distributionCenter.getState());
       po.setZipCode(distributionCenter.getZipCode());
       po.setZipCodePlusFour(distributionCenter.getZipCodePlusFour());
      
       BigDecimal quantityToOrder = new BigDecimal(demand.getBackorderQuantity());
       quantityToOrder = quantityToOrder.add(quantityToOrder.multiply(new BigDecimal(.2)));
      
       po.setQuantityToOrder(quantityToOrder.longValue());
      
       supplierManager.fulfillPurchaseOrder(po);
      
       }
      
      }


      In the JMX console I can see the bean deployed as ReplenishmentProcessorBean and the Queue that I defined is also created and called replenish, as you would expect.

      Is there an additional attribute I need to specify in the @EJB, or do I have to inject this using a different annotation? All the examples are either Java mains or JSP's, which can't inject the dependency.