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

Reply via email to