小编Meh*_*hdi的帖子

EJB无状态 - 私有成员初始化

我是EJB的新手,我正面临着我的第一个问题.我正在尝试使用无状态EJB中包含的@Schedule方法.我希望这个方法使用一个私有成员变量,该变量将在创建bean时设置:

这是一个简短的例子:

@Singleton
@LocalBean
@Startup
public class Starter {

     @PostActivate
     private void postActivate() {

         ScheduleEJB scheduleEjb = new ScheduleEJB("Hello");

     }

}
Run Code Online (Sandbox Code Playgroud)

和计划bean:

@Stateless
@LocalBean
public class ScheduleEJB {

     private String message;

     public ScheduleEJB() {
         super();
     }

     public ScheduleEJB(String message) {
         super();
         this.message= message;
     }

     @Schedule(second="*/3", minute="*", hour="*", dayOfMonth="*", dayOfWeek="*", month="*", year="*")
     private void printMsg() {

         System.out.println("MESSAGE : " + message);
     }
 }
Run Code Online (Sandbox Code Playgroud)

问题是我的"message"变量在printMsg()方法中打印时始终为null ...实现此目的的最佳方法是什么?

谢谢你的帮助 !

schedule ejb initialization stateless

2
推荐指数
1
解决办法
5186
查看次数

标签 统计

ejb ×1

initialization ×1

schedule ×1

stateless ×1