最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

CDI event on ejb module - Stack Overflow

programmeradmin0浏览0评论

I would use CDI event inside EE app. Inside ejb module there is an EJB want to fire an event that will be consumed inside web module . The EJB wants to fire event is :

@Singleton
@Startup
public class DailyWork {
  static final Logger logger =LoggerFactory.getLogger(DailyWork.class);

  @PostConstruct 
  public void automaticTimeout() {
       try {
           CcPayload payload= new CcPayload(cc.getId()+"","SOME PAYLOAD");
           new EventDispatcher().fire(payload);
       } 
       catch (Exception ex) {
           logger.warn("CAnnot calculate Balance for CC "+cc);
       }
   }    
 }

To fire the event I have this Dispatcher class (CDI bean on ejb module) :

import jakarta.enterprise.event.Event;
import jakarta.inject.Inject;

public class EventDispatcher {

  @Inject
  Event<CcPayload> event;


  public void fire(Object payload) {
    if (payload instanceof CcPayload){
        event.fire((CcPayload)payload);
    }
    else
        throw new UnsupportedOperationException();
    
    
  }
}

And the beans.xml in <ejb module/META-INF folder is :

<?xml version="1.0" encoding="UTF-8"?>
<beans version="4.0" bean-discovery-mode="all"
   xmlns=";
   xmlns:xsi=";
   xsi:schemaLocation=" .xsd">

</beans>

But the problem I am facing is the @Inject doesn't work and 'event' object is null when EJB use the disptacher to fire an event with payload.

Why Injection doesn't work ?

发布评论

评论列表(0)

  1. 暂无评论