We are planning to change Managed Beans to CDI beans. We used below code to invoke Service class in managed Bean.
@ManagedProperty("#{userService}")
private UserService userService; and setter method
For CDI bean, I replaced @ManagedProperty with @inject as shown below, and it is throwing following exception.
@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 is a plain interface with unimplemented methods and UserServiceImpl implements UserService interface. Please see below:
public interface UserService {
public List<User> getUserList();
}
public class UserServiceImpl implements UserService {
private UserDao userDao;
public List<User> getUserList() {
return userDao.getUserList();
}
}
Please let me know me how to invoke service interface in CDI beans?
Reading BalusC's answer on Spring JSF integration: how to inject a Spring component/service in JSF managed bean? tells me it is supposed to be supported that your Spring bean userService
should be injected into your CDI bean LoginController
.
But your UserServiceImpl
is not Serializable
which in CDI context means it is not passivation capable.
This is also what your Exception tells.
So either make your LoginController @RequestScoped
instead of @SessionScoped
so itself and @Inject
ed children do not require to be passivation capable (aka Serializable
).
Or make your UserServiceImpl
and DAO Implementations Serializable
(which imho is somewhat odd?).