【发布时间】:2024-01-13 21:20:01
【问题描述】:
这是我目前的情况:
@WebListener
public class WebListenerService implements HttpSessionListener{
.... implement methods
@Produces
@Dependent
public SessionDependentService sessionDependentService(){
}
}
@SessionScoped
@Named
public class AccountController implements Serializable{
//Injected properly and works as expected
@Inject
private SessionDependnetService sessionDependentService;
@Inject
@OnLogin
private Event<Account> accountEvent;
public void onLogin(){
accountEvent.fire(authenticatedAccount);
}
}
@SessionScoped
public class AccountObserver implements Serializable{
//This does not work. It is always null.
@Inject
private SessionDependnetService sessionDependentService;
public void onLoginEvent(@Observes @OnLogin final Account account) {
//When this methods is invoked
//the sessiondependentservice is always null here.
}
}
AccountController中,SessionDependentService被正确注入且不为null,而在AccountObserver中,始终为null。 p>
编辑: 使用参数注入的事件仍然会产生空值。
public void onLoginEvent(@Observes @OnLogin final Account account, final SessionDependnetService sessionDependentService) {
//When this methods is invoked
//the sessiondependentservice is always null here.
}
Netbeans 正确地将其突出显示为注入点。
为什么会这样?
我使用的是 Wildfly 8 服务器。
【问题讨论】:
标签: java jakarta-ee cdi wildfly-8