Using Java EE CDI it can happen that one would like to inject an @ApplicationScoped bean into a @SessionScoped bean.

@SessionScoped
public class MySessionBean implements Serializable {

    @Inject
    MyApplicationScopedBean appBean;
}

This situation can be problematic because @SessionScoped beans need to be Serializable, while @ApplicationScoped usually are not.

There is an interesting article which summarizes some possible strategies to avoid this issue, but you can also use an alternative (and more decoupled) approach: using CDI Events.

You usually need that injection point because you want to call a method of the @ApplicationScoped bean. You can obtain the same result firing a CDI Event and observing it.

@SessionScoped
public class MySessionBean implements Serializable {

    @Inject
    private Event<MyData> eventService;
    
    public void sendDataToOtherBean(MyData data) {
        eventService.fire(data);
    }
}
@ApplicationScoped
public class MyApplicationScopedBean {

    public void listenMyDataEvent(@Observes MyData event) {
        // do stuff
    }
}

According to CDI specification1, Events are passivation capable, so it is safe to inject them into serializable beans.

1) CDI spec 1.2, section 6.6.3, ‚ÄúPassivation capable dependencies‚ÄĚ