[jboss-user] [JBoss/Spring Integration] - Is it SpringLifecycleInterceptor or just me?

Arno Werr do-not-reply at jboss.com
Sat Jul 29 15:39:07 EDT 2006


The other day I decided to play a little with batch processing on JBoss + Spring EJB3 and all.
Created this stateful session bean to force the Entity manager do a batch job for me on remove


  | @Stateful
  | @Interceptors(SpringLifecycleInterceptor.class)
  | @TransactionAttribute(NOT_SUPPORTED)
  | public class StetefulBean implements Init {
  |     @PersistenceContext(unitName = "titan", type = EXTENDED)
  |     private EntityManager manager;
  |  
  |     @Spring(jndiName = "spring-pojo", bean = "statefulService")
  |     private TravelService service;
  | 
  |     @PostConstruct
  |     public void postConstruct() {
  |         service.setManager(manager);
  |     }
  | 
  |     public void initAirports(int index) {
  |         if (isInit(Airport.class)) {
  |             return;
  |         }
  |         List<Airport> lst = new ArrayList<Airport>();
  |        
  |         for (int i = 0; i < index; i++) {
  |             Airport port = new Airport();
  |             if (i % 2 == 0) {
  |                 port.setName("Denver " + (i + 1));
  |                 port.setAirportCode("dnvr_" + (i + 1));
  |             } else {
  |                 port.setName("Hoover " + (i + 1));
  |                 port.setAirportCode("hvr_" + (i + 1));
  |             }
  |             lst.add(port);
  |         }
  |         service.createAirports(lst);
  |     }
  |    
  |     @Remove
  |     @TransactionAttribute(REQUIRED)
  |     public void flush() {
  |         // syncrhonize with database;
  |     }
  | 
  |     private boolean isInit(Class clazz) {
  |         return service.getNumberOfObjects(clazz) == 0 ? false : true;
  |     }
  | }
  | 

I am using this SpringLifecycleInterceptor.class from the JBoss+Spring distribution. Unfortunately, that one is giving me kinda trouble throwing all kind of exceptions

OK. Made my own interceptor a la SpringLifecycleInterceptor

  | public class StatefulBeanInterceptor extends SpringPassivationInterceptor {
  |     private static final long serialVersionUID = 1243234L;
  |     @PostConstruct
  |     public void postConstruct(InvocationContext ctx) throws Throwable {
  |         inject(ctx.getBean());
  |         ctx.proceed();
  |     }
  | }
  | 

Wired it up. @Interceptors(StatefulBeanInterceptor.class) 
Ran JBoss. 
No problemo! Works like a charm. There might be something wrong with that SpringLifecyleInterceptor thing from the distribution, or mine might be a bit obsolete (I've downloaded sometime late June, I guess). No idea...

Another question - how to inject EntityManager from Spring configuration. Currently I am using annotations and pushing manager to the service layer. Yet wiring it up from outside, Spring, I mean, would be kinda kool to me.

Cheers,
Arno

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3961698#3961698

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3961698



More information about the jboss-user mailing list