[英]How to invoke Service Class Interface in CDI bean
我們計划將 Managed Beans 更改為 CDI bean。 我們使用以下代碼在托管 Bean 中調用 Service class。
@ManagedProperty("#{userService}")
private UserService userService; and setter method
對於CDI bean,我用@inject 替換了@ManagedProperty,如下所示,它拋出了以下異常。
@SessionScoped
@Named
public class LoginController implements Serializable {
@Inject
private UserService userService;
}
org.apache.webbeans.exception.WebBeansDeploymentException: Passivation capable beans must satisfy passivation capable dependencies.
UserService 是一個帶有未實現方法的普通接口,而 UserServiceImpl 實現了 UserService 接口。 請看下面:
public interface UserService {
public List<User> getUserList();
}
public class UserServiceImpl implements UserService {
private UserDao userDao;
public List<User> getUserList() {
return userDao.getUserList();
}
}
請讓我知道如何在 CDI bean 中調用服務接口?
閱讀 BalusC 關於Spring JSF 集成的答案:如何在 Z798476CFD7031D68627 中注入 Spring 組件/服務? 告訴我應該支持您的 Spring bean userService
應該注入您的 CDI bean LoginController
。
但是您的UserServiceImpl
不是Serializable
,這在 CDI 上下文中意味着它不具備鈍化能力。
這也是您的異常所告訴的。
所以要么讓你的 LoginController @RequestScoped
而不是@SessionScoped
所以它本身和@Inject
ed孩子不需要鈍化能力(又名Serializable
)。 或者使您的UserServiceImpl
和 DAO 實現可Serializable
(恕我直言有點奇怪?)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.