If you list both of these interceptors in your Interceptor.Classes init-param in the order you want them to initialize they will initialize in the specified order. You already list SpringInterceptor there. I think if you just insert Stripersist before it then you'll be in business. (Once you do that then you should remove their packages from Extension.Packages to improve startup speed.)
-Ben On Wed, May 26, 2010 at 10:25 PM, Nikolaos Giannopoulos < nikol...@brightminds.org> wrote: > All, > > After a lot of digging I have unfortunately gotten nowhere. > > I have found that the lifecycles that Stripersist intercepts are: > @Intercepts({LifecycleStage.RequestInit, LifecycleStage.RequestComplete}) > > Whereas the Spring Interceptor intercepts at: > @Intercepts(LifecycleStage.ActionBeanResolution) > > SO if both were initialized at "execution" intercept time then I suspect we > would not have any issues. > > However the NPE tells me that this issue appears due to order of > "initialization" of Interceptors. > I have found how to order the "execution" of Interceptors BUT not the > "initialization" of Interceptors. > > Does anyone know how I can get Stripersist to initialize BEFORE Spring > Interceptor? > I have the following web.xml snippet and could really use a lot of help... > PLEASE... > > <listener> > > <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class><!-- > Automatically loads: /WEB-INF/applicationContext.xml --> > </listener> > > <filter> > <filter-name>StripesFilter</filter-name> > > <filter-class>net.sourceforge.stripes.controller.StripesFilter</filter-class> > ... > <init-param> > <param-name>Interceptor.Classes</param-name> > > <param-value>net.sourceforge.stripes.integration.spring.SpringInterceptor</param-value> > </init-param> > <init-param> > <param-name>Extension.Packages</param-name> > <param-value> > org.lightagents.ui.stripes.extensions, > org.lightagents.ui.stripes.reload.extensions, > org.stripesstuff.stripersist, > net.sourceforge.stripes.integration.spring > </param-value> > </init-param> > ... > > Stripersist is an awesome package and we have even built a shard layer on > top of it... I surely hope there is a solution for it to play nice with > Spring in this case. > > Thanks in Advance! > > --Nikolaos > > > > Nikolaos Giannopoulos wrote: > > Still trying to resolve this issue... and I think I have made some progress > in ZERO'ing in on a reduced version of the issue. > > The following code works fine: > > public class BaseActionBean implements ActionBean { > @SpringBean protected ModalityDao modalityDao; > ... > > @Repository("modalityDao") > public class ModalityDaoImpl extends BaseDaoImpl<Modality, Integer> > implements ModalityDao { > public List<Modality> findAll() { > return (this.load()); > } > > However if I add a @PostConstruct on the above DAO as follows I get the > exception reported previously (see below again): > > public class BaseActionBean implements ActionBean { > @SpringBean protected ModalityDao modalityDao; > ... > > @Repository("modalityDao") > public class ModalityDaoImpl extends BaseDaoImpl<Modality, Integer> > implements ModalityDao { > public List<Modality> findAll() { > return (this.load()); > } > @PostConstruct > private void init() { > this.findAll(); > } > > It would appear that Spring's interceptor is doing its work BEFORE > Stripersist's interceptor gets its chance to initialize. > > Because in digging through the Stripersist code we have: > > /** > * Called by Stripes during initialization. > */ > public void init(Configuration configuration) > ... > URL url = > Thread.currentThread().getContextClassLoader().getResource("/META-INF/persistence.xml"); > ... > init(url); > > ... and in turn init(url) calls ... > > public void init(URL xml) > ... > entityManagerFactories = new ConcurrentHashMap<String, > EntityManagerFactory>(); > > and that would clearly appear that entityManagerFactories is initialized > however it is NULL when we run the 2nd code above. > > It would APPEAR we want the Stripersist interceptor to initialize BEFORE > the Spring interceptor. > > Anyone know how we can accomplish this besides creating a Spring-Stripes > extension class that simply calls them in the desired order??? > > --Nikolaos > > > > > Nikolaos Giannopoulos wrote: > > Freddy (and Aaron), > > Offhand THANK YOU for the help! While it DID help I'm afraid I'm not > there yet... . > > So I added the @PostConstruct annotation (and <context:annotation-config > /> in the applicationContext.xml to register things) and have the > following code: > > @Service("modalityService") > public class ModalityServiceImpl implements ModalityService { > > @Autowired > private ModalityDao modalityDao; > > private ModalityCache modalityCache; > > public ModalityServiceImpl() { > } > > @PostConstruct > public void initService() { > List<Modality> modalityList = this.modalityDao.findAll(); > this.modalityCache = new ModalityCache(); > this.modalityCache.init(modalityList); > } > > And the @PostConstruct indeed helped as the initService method is getting > executed however now I am back to the issue with Stripersist generating a > NPE in the following method call: > > /** > * Finds the EntityManagerFactory which is associated with the > specified > * persistence unit. Normally you shouldn't use this class because > * Stripersist won't clean up any EntityManagers that you create. > * > * @param persistenceUnit the name of the persistence unit > * @return an EntityManagerFactory or null > */ > public static EntityManagerFactory getEntityManagerFactory(String > persistenceUnit) > { > return entityManagerFactories.get(persistenceUnit); > } > > Where: entityManagerFactories is NULL!!!!! So it is almost like even > though the @PostConstruct annotated method gets invoked on bean post > creation a layer of the onion has been lifted and now the problem appears > that Stripersist hasn't completed its initialization. I have to think there > MUST be a way to solve this!!! AHhhhhh??? > > Full stack trace below.... > > Many Thanks, > > --Nikolaos > > > [#|2010-05-26T14:07:50.795-0400|INFO|glassfishv3.0|javax.enterprise.system.std.com.sun.enterprise.v3.services.impl|_ThreadID=11;_ThreadName=FelixStartLevel;|[14:07:50,774] > ERROR > org.springframework.web.context.ContextLoader.initWebApplicationContext - > Context initialization failed > org.springframework.beans.factory.BeanCreationException: Error creating > bean with name 'modalityService': Invocation of init method failed; nested > exception is java.lang.NullPointerException > at > org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:147) > at > org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:350) > at > org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1331) > at > org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473) > at > org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409) > at java.security.AccessController.doPrivileged(Native Method) > at > org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380) > at > org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264) > at > org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) > at > org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261) > at > org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185) > at > org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164) > at > org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429) > at > org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728) > at > org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380) > at > org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255) > at > org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199) > at > org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45) > at > org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:4591) > at > com.sun.enterprise.web.WebModule.contextListenerStart(WebModule.java:535) > at > org.apache.catalina.core.StandardContext.start(StandardContext.java:5193) > at com.sun.enterprise.web.WebModule.start(WebModule.java:499) > at > org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:928) > at > org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:912) > at > org.apache.catalina.core.StandardHost.addChild(StandardHost.java:694) > at > com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1933) > at > com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1605) > at com.sun.enterprise.web.WebApplication.start(WebApplication.java:90) > at org.glassfish.internal.data.EngineRef.start(EngineRef.java:126) > at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:241) > at > org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:236) > at > com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:339) > at > com.sun.enterprise.v3.server.ApplicationLoaderService.processApplication(ApplicationLoaderService.java:340) > at > com.sun.enterprise.v3.server.ApplicationLoaderService.postConstruct(ApplicationLoaderService.java:163) > at > com.sun.hk2.component.AbstractWombImpl.inject(AbstractWombImpl.java:174) > at com.sun.hk2.component.ConstructorWomb$1.run(ConstructorWomb.java:87) > at java.security.AccessController.doPrivileged(Native Method) > at > com.sun.hk2.component.ConstructorWomb.initialize(ConstructorWomb.java:84) > at com.sun.hk2.component.AbstractWombImpl.get(AbstractWombImpl.java:77) > at > com.sun.hk2.component.SingletonInhabitant.get(SingletonInhabitant.java:58) > at com.sun.hk2.component.LazyInhabitant.get(LazyInhabitant.java:107) > at > com.sun.hk2.component.AbstractInhabitantImpl.get(AbstractInhabitantImpl.java:60) > at > com.sun.enterprise.v3.server.AppServerStartup.run(AppServerStartup.java:236) > at > com.sun.enterprise.v3.server.AppServerStartup.start(AppServerStartup.java:128) > at com.sun.enterprise.module.bootstrap.Main.launch(Main.java:457) > at com.sun.enterprise.module.bootstrap.Main.launch(Main.java:401) > at org.jvnet.hk2.osgiadapter.HK2Main.start(HK2Main.java:125) > at > org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:640) > at org.apache.felix.framework.Felix.activateBundle(Felix.java:1700) > at org.apache.felix.framework.Felix.startBundle(Felix.java:1622) > at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:915) > at org.jvnet.hk2.osgimain.Main.start(Main.java:140) > at > org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:640) > at org.apache.felix.framework.Felix.activateBundle(Felix.java:1700) > at org.apache.felix.framework.Felix.startBundle(Felix.java:1622) > at > org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1077) > at > org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:264) > at java.lang.Thread.run(Thread.java:637) > Caused by: java.lang.NullPointerException > at > org.stripesstuff.stripersist.Stripersist.getEntityManagerFactory(Stripersist.java:401) > at > org.stripesstuff.stripersist.Stripersist.getEntityManager(Stripersist.java:495) > at > org.lightagents.ws.dao.impl.stripersist.BaseDaoImpl.load(BaseDaoImpl.java:70) > at > org.lightagents.ws.dao.impl.stripersist.ModalityDaoImpl.load(ModalityDaoImpl.java:50001) > at > org.lightagents.ws.dao.impl.stripersist.BaseDaoImpl.load(BaseDaoImpl.java:39) > at > org.lightagents.ws.dao.impl.stripersist.ModalityDaoImpl.load(ModalityDaoImpl.java:50001) > at > org.lightagents.ws.dao.impl.stripersist.ModalityDaoImpl.findAll(ModalityDaoImpl.java:20) > at > org.lightagents.ws.service.impl.ModalityServiceImpl.initService(ModalityServiceImpl.java:35) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) > at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) > at java.lang.reflect.Method.invoke(Method.java:597) > at > org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:297) > at > org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:250) > at > org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:144) > ... 57 more > |#] > > > Freddy Daoud wrote: > > Hi Nikolaos, > > > > I guess what I need is a WAY to perform POST initialization on this > Spring managed Service object. If I was dealing with an ActionBean then > an @AFTER on a particular life cycle event I imagine would do the trick > but this is not an Action Bean. > > > You are right, it is a bad idea to do any work in the constructor in > this case; you need to let Spring finish its wiring. > > Indeed there is a standard annotation for doing post-initialization > work: > javax.annotation.PostConstruct. Spring recognizes this annotation when > its > annotation post processor is registered.[1] > > So all you need is something like: > > @PostConstruct > public void init() { > // do initialization work > // the name of the method can be something else than 'init' > } > > I use this mechanism a lot and it works well. > Hope that helps. > > Cheers, > Freddy > > [1]:http://static.springsource.org/spring/docs/2.5.x/reference/beans.html#beans-postconstruct-and-predestroy-annotations > > ------------------------------ > > > > > ------------------------------------------------------------------------------ > > > _______________________________________________ > Stripes-users mailing list > Stripes-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/stripes-users > >
------------------------------------------------------------------------------
_______________________________________________ Stripes-users mailing list Stripes-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/stripes-users