3

MessageListenerを実装し、いくつかのEJB属性を持つメッセージ駆動型Bean(MDB)がありますが、それらは非注入型であるため手動で注入する必要があります。 MDBにはリソースとCDI Beanもあり、細かく注入できます。ステートレスEJBがメッセージドリブンBean(MDB)に挿入されていません

なぜEJBが自動的に挿入されないのですか?私は、アプリケーションの他の部分でNotificationService EJBを使用し、それらが注入されます。どのように問題を把握するかについての手がかりは?

私はWeblogic 12.1.3から何のエラーもありませんので、ここで何が起こっているのか分かりません。私のコードは(デバッグのためのトレースがいっぱいです)。

@MessageDriven(name = "MailMessageConsumer", description = "JMS consumer", mappedName = MailJndiConfiguration.JNDI_QUEUE, 
    activationConfig = { 
      @ActivationConfigProperty(propertyName = "acknowledgeMode", 
             propertyValue = "Auto-acknowledge"), 
      @ActivationConfigProperty(propertyName = "destinationType", 
             propertyValue = "javax.jms.Queue") 
    }) 
@TransactionAttribute(TransactionAttributeType.REQUIRED) 
@MessageReceiver(responsibility = "Consumes JMS messages of type MailMessage") 
public class MailMessageConsumer implements MessageListener { 
    private static final Logger log = LoggerFactory.getLogger(MailMessageConsumer.class); 
    @Resource 
    private MessageDrivenContext messageDrivenContext; 
    @EJB 
    private NotificationService notificationService; 
    @EJB 
    private MailClient mailClient; 
    @Inject 
    private ApplicationInformation applicationInformation; 

    @Override 
    public void onMessage(Message message) { 
     if (mailClient == null) { 
      log.error("mailClient object is null"); 
      try { 
       log.info("Instantiating MailClient manually..."); 
       mailClient = BeanManagerHelper.getReference(MailClient.class); 
      } catch (Exception e) { 
       log.error("Cannot instantiate MailClient manually", e); 
      } 
     } 
     if (notificationService == null) { 
      log.error("notificationService object is null"); 
      try { 
       log.info("Instantiating NotificationService manually..."); 
       notificationService = BeanManagerHelper.getReference(NotificationService.class); 
      } catch (Exception e) { 
       log.error("Cannot instantiate NotificationService manually", e); 
      } 
     } 
     // This never happens 
     if (applicationInformation == null) { 
      log.error("applicationInformation object is null"); 
     } 
     // This never happens 
     if (messageDrivenContext == null) { 
      log.error("messageDrivenContext object is null"); 
     } 
     deliverMessage(message); 
    } 

    private void deliverMessage(Message message) { 
     // Not important 
    } 

    private MailMessage retrieveMessage(Message message) { 
     // Not important 
    } 

    private void sendEmail(MailMessage mailMessage) { 
     // Not important 
    } 
} 

MailClient EJB:

@Stateless 
@LocalBean 
@TransactionAttribute(TransactionAttributeType.MANDATORY) 
@Service 
public class MailClient { 
    private static final Logger logger = LoggerFactory.getLogger(MailClient.class); 
    @Resource(mappedName = MailJndiConfiguration.JNDI_MAIL_SESSION) 
    private Session mailSession; 
    @EJB 
    private NotificationService notificationService; 
    @Inject 
    private ApplicationInformation applicationInformation; 

    enum ValidationError { 
     NULL_OBJECT("Mail message is null"), 
     CONTENT_TYPE_EMPTY("Content type not initialized"), 
     BODY_EMPTY("Message body content is empty"); 
     private static final String ERROR_MESSAGE_PREFIX = "Invalid mail message: "; 
     private String message = ERROR_MESSAGE_PREFIX; 

     ValidationError(String message) { 
      this.message += message; 
     } 

     public String getMessage() { 
      return message; 
     } 
    } 

    public void sendMail(MailMessage mailMessage) throws MailMessageSendingException { 
     // Not important 
    } 
} 

NotificationServiceのEJB:

@Stateless 
@LocalBean 
@TransactionAttribute(TransactionAttributeType.MANDATORY) 
@Service 
public class NotificationService { 
    private static final Logger logger = LoggerFactory.getLogger(NotificationService.class); 
    @PersistenceContext(unitName = "myEntityManager") 
    private EntityManager entityManager; 
    @EJB 
    private NotificationPendingMessageValidator notificationPendingMessageValidator; 
    @EJB 
    private NotificationFinder notificationFinder; 
    @Inject 
    private ApplicationInformation applicationInformation; 

    public NotificationPendingMessageEntity saveNotificationMessageForDeferredMail(NotificationPendingMessageEntity notificationPendingMessageEntity) throws ValidationException { 
     // Not important 
    } 

    public List<NotificationPendingMessageEntity> findNotificationPendingMessageEntities(TimeSlot timeSlot) { 
     // Not important 
    } 

    @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) 
    public NotificationMailEntity createNewMailEntity() { 
     // Not important 
    } 

    @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) 
    public void updateMailEntity(NotificationMailEntity mailEntity) { 
     // Not important 
    } 

    public void createNotificationMessageProcessedEntity(NotificationProcessedMessageEntity notificationProcessedMessageEntity) { 
     // Not important 
    } 

    public void removeNotificationMessagePendingEntity(NotificationPendingMessageEntity notificationPendingMessageEntity) { 
     // Not important 
    } 

    public void reportMailFailure(NotificationMailEntity mailEntity, String failureNotice) { 
     // Not important 
    } 
} 
+2

良い質問ですが、私の同僚は同じ問題を抱えています – Lastnico

答えて

2

ではなく、EJBを注入するための@Injectを使用して、私はこの問題に関連していないのJavadocとメソッドの実装を削除しました@EJBの注釈は正常に機能します。だから、いくつかのWeblogicのパッチに問題があるはずです。別のWeblogic(同じバージョン、別のパッチ)でテストしてもうまく動作するからです。

+0

万が一、正確なパッチ?私たちは12.2.1の正確なケースを持っていました。 – meskobalazs

+0

私は申し訳ありません、わかりません。私はWeblogicの管理サイドを担当していませんでした。 –

+0

ありがとうと:) – meskobalazs

関連する問題