Basically only tomcat session is persisted. Now sessionscoped beans should
be too when existing but no more
Le 30 déc. 2012 16:30, "Howard W. Smith, Jr." <[email protected]> a
écrit :
> Is TomEE 1.5.2 SNAPSHOT persistence across restarts working as designed? I
> know this is a Tomcat7 feature, but maybe I'm missing something in my code.
> My CDI @ApplicationScoped bean references @Stateful EJB in @PostConstruct
> and @Predestroy to read and write data. The @PreDestroy code works as
> designed, but the @PostConstruct code never executes or shows up in the
> log. What am I missing? Please see below.
>
> Below is code in CDI @ApplicationScoped @PostConstruct and @PreDestroy
>
> @PostConstruct
> public void init() {
> tripDatesInQueueForGoogleCalendarUpdate = null;
> if
>
> (applicationStatefulSessionBean.getTripDatesInQueueForGoogleCalendarUpdate()
> != null &&
>
>
> !applicationStatefulSessionBean.getTripDatesInQueueForGoogleCalendarUpdate().isEmpty())
> {
>
> tripDatesInQueueForGoogleCalendarUpdate =
> applicationStatefulSessionBean.
>
> getTripDatesInQueueForGoogleCalendarUpdate();
> log("ApplicationScopeBean.init():
> tripDatesInQueueForGoogleCalendarUpdate = " +
>
>
> "applicationStatefulSessionBean.getTripDatesInQueueForGoogleCalendarUpdate()
> completed; " +
> "tripDatesInQueueForGoogleCalendarUpdate.size() = " +
> tripDatesInQueueForGoogleCalendarUpdate.size());
> }
>
> }
>
> @PreDestroy
> private void destroy() {
> log("ApplicationScopeBean.destroy() invoked");
> if (tripDatesInQueueForGoogleCalendarUpdate != null &&
> !tripDatesInQueueForGoogleCalendarUpdate.isEmpty()) {
> String queue = "";
> for (Date d : tripDatesInQueueForGoogleCalendarUpdate) {
> if (queue.length() > 0) {
> queue += ", ";
> }
> queue += new DateTime(d).toString("MM/dd/yyyy");
> }
> log("ApplicationScopeBean.destroy():
> tripDatesInQueueForGoogleCalendarUpdate include " + queue);
>
> applicationStatefulSessionBean.
>
>
> setTripDatesInQueueForGoogleCalendarUpdate(tripDatesInQueueForGoogleCalendarUpdate);
>
> log("ApplicationScopeBean.destroy():
> applicationStatefulSessionBean." +
>
>
> "setTripDatesInQueueForGoogleCalendarUpdate(tripDatesInQueueForGoogleCalendarUpdate)
> " +
> "completed; tripDatesInQueueForGoogleCalendarUpdate.size()
> = " +
> tripDatesInQueueForGoogleCalendarUpdate.size());
> }
> }
>
>
>
> Below is the @Stateful bean
>
> /*
> * To change this template, choose Tools | Templates
> * and open the template in the editor.
> */
> package pf;
>
> import java.io.Serializable;
>
> import java.util.Date;
> import java.util.List;
>
> import javax.ejb.Stateful;
>
> /**
> *
> * @author Administrator
> *
> *
>
> http://stackoverflow.com/questions/5387267/persisting-session-of-tomcat-server-application-between-re-deploymets-from-myecl
> *
>
> http://tomcat.apache.org/tomcat-7.0-doc/config/manager.html#Persistence_Across_Restarts
> */
> @Stateful
> public class ApplicationStatefulSessionBean implements Serializable {
>
> private List<Date> tripDatesInQueueForGoogleCalendarUpdate;
>
> public List<Date> getTripDatesInQueueForGoogleCalendarUpdate() {
> return tripDatesInQueueForGoogleCalendarUpdate;
> }
>
> public void setTripDatesInQueueForGoogleCalendarUpdate(List<Date>
> tripDatesInQueueForGoogleCalendarUpdate) {
> this.tripDatesInQueueForGoogleCalendarUpdate =
> tripDatesInQueueForGoogleCalendarUpdate;
> }
>
> }
>