13 Replies Latest reply on Nov 17, 2006 12:37 PM by iradix

    Application Startup Actions

    iradix

      Is anyone using seam components to perform actions on the database when their application starts? With Seam 1.0 I had a few SFSB that were application scoped and used the @Startup and @Create methods to check if certain necessary data was available and create it if it wasn't. These are actions like determining if there is at least one administrative account and creating a default one if not, or defining static categories. These stopped working in 1.1 and rather than figuring out why, I'm looking for a better way to perform these types of actions. My two chief problems were/are:

      1) These don't need to be SFSB because they only exists to fire off their create methods, yet I can't do that on application startup without scoping them to the application, and I can't place an SLSB in application scope.

      2) I have no conversation available when the application starts up and this wreaks havoc with my DAOs which expect to be able to inject an SMPC.

      Any ideas?

        • 1. Re: Application Startup Actions
          gavin.king

          I would really rather prefer if you figured out what changed in 1.1 that broke your code, and let me know...

          • 2. Re: Application Startup Actions
            iradix

            Fair enough. I'll look into it some more when I'm testing the page parameter converter change in a little bit. Either way though, I'm curious if you or anyone else has a better solution? Creating an SFSB only to have it remove itself from the application context in it's own @Create method doesn't exactly strike me as the most readable code :)

            • 3. Re: Application Startup Actions
              iradix

              Ok Gavin, it looks to me like the problem stems from the SeamListener trying to instantiate the application scoped SFSB before Jboss is initialized. Adding depends="org.jboss.seam.core.Ejb" doesn't seem to help. Stack trace follows

              -Exception sending context initialized event to listener instance of class org.j
              boss.seam.servlet.SeamListener
              org.jboss.seam.InstantiationException: Could not instantiate Seam component: sta
              teLoader
               at org.jboss.seam.Component.newInstance(Component.java:1662)
               at org.jboss.seam.contexts.Lifecycle.startup(Lifecycle.java:153)
               at org.jboss.seam.contexts.Lifecycle.endInitialization(Lifecycle.java:12
              7)
               at org.jboss.seam.init.Initialization.init(Initialization.java:323)
               at org.jboss.seam.servlet.SeamListener.contextInitialized(SeamListener.j
              ava:33)
               at org.apache.catalina.core.StandardContext.listenerStart(StandardContex
              t.java:3669)
               at org.apache.catalina.core.StandardContext.start(StandardContext.java:4
              104)
               at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase
              .java:759)
               at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:73
              9)
               at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524)
               at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.ja
              va:589)
               at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.j
              ava:536)
               at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:471
              )
               at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1102)
               at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java
              :311)
               at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(Lifecycl
              eSupport.java:119)
               at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1020)
               at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
               at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1012)
               at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442
              )
               at org.apache.catalina.core.StandardService.start(StandardService.java:4
              50)
               at org.apache.catalina.core.StandardServer.start(StandardServer.java:683
              )
               at org.apache.catalina.startup.Catalina.start(Catalina.java:537)
               at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
               at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
              java:39)
               at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
              sorImpl.java:25)
               at java.lang.reflect.Method.invoke(Method.java:585)
               at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:271)
               at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:409)
              Caused by: javax.naming.NamingException: Local server is not initialized
               at org.jnp.interfaces.LocalOnlyContextFactory.getInitialContext(LocalOnl
              yContextFactory.java:45)
               at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:6
              67)
               at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247
              )
               at javax.naming.InitialContext.init(InitialContext.java:223)
               at javax.naming.InitialContext.<init>(InitialContext.java:197)
               at org.jboss.seam.util.Naming.getInitialContext(Naming.java:35)
               at org.jboss.seam.util.Naming.getInitialContext(Naming.java:47)
               at org.jboss.seam.Component.instantiateSessionBean(Component.java:992)
               at org.jboss.seam.Component.instantiate(Component.java:979)
               at org.jboss.seam.Component.newInstance(Component.java:1658)
               ... 28 more
              
              




              • 4. Re: Application Startup Actions

                I have a couple of components accessing the database and caching data for the application. I didn't get any trouble moving from Seam 1.0 to Seam 1.1

                They are defined as follow:

                @Scope(ScopeType.APPLICATION)
                @Name("someComponent")
                public class SomeComponent {
                
                 @Create
                 public void startup() throws Exception {
                 ...
                 }
                }
                


                • 5. Re: Application Startup Actions
                  iradix

                  I think the problem here has to do with the @Startup annotation. I take it you're not using that?

                  • 6. Re: Application Startup Actions

                    That's right, I'm not using the @Startup annotation.

                    • 7. Re: Application Startup Actions

                      Actually I do.
                      I think the previous code is not the one I intended to copy. Here is what I use:

                      @Scope(ScopeType.APPLICATION)
                      @Intercept(InterceptionType.NEVER)
                      @Startup(depends = {"pojoCache"})
                      @Name("resourcesManager")
                      public class ResourcesManager {
                      
                       private static final Log log = LogFactory.getLog(ResourcesManager.class);
                      
                       private transient PojoCache pojoCache = org.jboss.seam.core.PojoCache.instance();
                      
                       private EntityManager entityManager;
                      
                       @Create
                       public void startup() throws Exception {
                       ...
                       }
                      }
                      


                      • 8. Re: Application Startup Actions
                        iradix

                        Ok. Well that's making it look increasingly like my problem is with when JBoss initializes since you are using a POJO rather than a session bean. Has this changed between versions?

                        • 9. Re: Application Startup Actions
                          gavin.king

                          Is this on JBoss AS? Or E-EJB3?

                          • 10. Re: Application Startup Actions
                            iradix

                            E-EJB3

                            • 11. Re: Application Startup Actions
                              gavin.king

                              Well, that makes more sense, since Seam is responsible for starting the Ejb component during its startup phase.

                              Put:

                              depends="org.jboss.seam.core.ejb"


                              on your component (no caps!)

                              • 12. Re: Application Startup Actions
                                iradix

                                Huh, don't know where I got the capital E from, I thought I just cut and pasted from the @Name. I'll give it a shot and let you know if it fixes the problem.

                                • 13. Re: Application Startup Actions
                                  iradix

                                  That fixed it. Thanks.