0

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?

PriyaN
  • 23
  • 4
  • Is UserService a CDI-Bean either with @Named annotation? And you didn't add the full exception with trace. – Selaron Oct 16 '19 at 19:27
  • @selaron : UserService is a plain interface with unimplemented methods and UserServiceImpl implements UserService interface. – PriyaN Oct 16 '19 at 19:39
  • Editing the post to include details is perfectly right. THis is still not the full exception stack trace but better than before. – Selaron Oct 16 '19 at 19:45
  • Who is managing the userService bean? If it should be a CDI bean, UserServiceImpl should be annotated @Named (and appropriate scope). And/Or it must be serializable because your LoginController is SessionScopend and therefore needs to be serializable plus all fields need to be Serializable. – Selaron Oct 16 '19 at 19:46
  • Looks like this is a SpringFramework bean – Selaron Oct 16 '19 at 19:51

1 Answers1

1

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 @Injected children do not require to be passivation capable (aka Serializable). Or make your UserServiceImpl and DAO Implementations Serializable (which imho is somewhat odd?).

Selaron
  • 6,105
  • 4
  • 31
  • 39