【发布时间】:2015-11-20 12:53:22
【问题描述】:
我有调用异步操作的无状态 bean。我想将我的另一个 bean 注入到这个 bean 中,它存储(或者更确切地说应该存储)正在运行的进程状态。这是我的代码:
处理器:
@Stateless
public class Processor {
@Asynchronous
public void runLongOperation() {
System.out.println("Operation started");
try {
for (int i = 1; i <= 10; i++) {
//Status update goes here...
Thread.sleep(1000);
}
} catch (InterruptedException e) {
}
System.out.println("Operation finished");
}
}
处理器处理程序:
@ManagedBean(eager = true, name="ph")
@ApplicationScoped
public class ProcessorHandler implements RemoteInterface {
public String status;
@EJB
private Processor processor;
@PostConstruct
public void init(){
status = "Initialized";
}
@Override
public void process() {
processor.runLongOperation();
}
public String getStatus() {
return status;
}
}
ProcessHandler 的Process 方法绑定到一个按钮。 我想从处理器内部修改 ProcessHandler bean 的状态,以便向用户显示更新的状态。
我尝试使用@Inject、@ManagedProperty 和@EJB 注释,但没有成功。
我正在使用 Eclipse EE 开发的 Websphere v8.5 上测试我的解决方案。
将注入添加到处理器类时...
@Inject
public ProcessorHandler ph;
我收到错误:
The @Inject java.lang.reflect.Field.ph reference of type ProcessorHandler for the <null> component in the Processor.war module of the ProcessorEAR application cannot be resolved.
【问题讨论】:
-
那么我应该如何处理这个问题?你能给我一些建议吗?