-
1. Re: something like @Startup
damianharvey.damianharvey.gmail.com Feb 25, 2008 10:17 AM (in response to marx3)If you combine a class with @Startup and a method with @Create you'll get a method executing at startup. Sounds like what you're after.
Cheers,
Damian.
-
2. Re: something like @Startup
nickarls Feb 25, 2008 10:33 AM (in response to marx3)If you plan to use seam components then placing an observer on org.jboss.seam.postInitialization might be a good idea. If you pick the connection directly from JNDI then an application scoped bean with @Startup should do...
-
3. Re: something like @Startup
marx3 Feb 25, 2008 12:39 PM (in response to marx3)What type of component should I use?
Seam documentation says:the @Startup annotation, which may be applied to any application or session scoped component.
But I don't need this component later, so declaring it as application or session component isn't good idea.
Maybe I should simply declare servlet with load-on-startup=1 ? -
4. Re: something like @Startup
nickarls Feb 25, 2008 12:53 PM (in response to marx3)Well, one app scoped bean isn't usually that harmful to have around (especially since your wouldn't keep that many resources).
If you want to get rid of it, you could probably have it remove itself from the context once its done... -
5. Re: something like @Startup
marx3 Feb 25, 2008 1:21 PM (in response to marx3)I made such code, but during startup runSQL() method isn't executed
@Stateful @Scope(ScopeType.APPLICATION) @Startup public class UpdaterManagerBean implements UpdaterManager { @Logger private Log log; @Remove @Destroy public void destroy() { } @Create @Override public void runSQL(){ log.info("###########################################"); } }
-
6. Re: something like @Startup
taccart.thierry.accart.name Feb 25, 2008 1:29 PM (in response to marx3)I'm not sure, but maybe should you have a look at this post from Pete Muir:
Doing something at startup with Seam (...)
The easiest way is to observe the org.jboss.seam.postInitialization event (which occurs right after Seam finishes initializing):
Read more on http://in.relation.to -
7. Re: something like @Startup
nickarls Feb 25, 2008 1:33 PM (in response to marx3)Keeping it simple, try
@Name("bootstrapper") public class UpdateManagerPOJO { @Logger private Log log; @Observer("org.jboss.seam.postInitialization") public void runSQL() { log.info("dropping db"); } }
-
8. Re: something like @Startup
marx3 Feb 25, 2008 2:09 PM (in response to marx3)ok, observer did the trick, thank you all :)
-
9. Re: something like @Startup
jeff87 Feb 28, 2008 6:48 PM (in response to marx3)I too need to do something similar to this but am having trouble. This works:
@Name("startupObserver") public class StartupObserver { @Logger private Log log; /** * This is called by seam after initialization * has finished. */ @Observer("org.jboss.seam.postInitialization") public void observe() { log.info("About to load system properties"); } }
but this fails and using @In instead of @PersistenceContext fails too:
@Name("startupObserver") public class StartupObserver { @Logger private Log log; @PersistenceContext private EntityManager entityManager; /** * This is called by seam after initialization * has finished. */ @Observer("org.jboss.seam.postInitialization") public void observe() { log.info("About to load system properties"); } }
with the message:
Exception sending context initialized event to listener instance of class org.jboss.seam.servlet.SeamListener
java.lang.RuntimeException: Could not create Component: startupObserverIf the app is initialized, shouldn't the entityManager be available? I'm using Seam 2.0.1 if that matters.
-
10. Re: something like @Startup
jeff87 Feb 28, 2008 7:28 PM (in response to marx3)Nevermind, throwing in a @Stateless worked.
-
11. Re: something like @Startup
monkeyden Feb 28, 2008 9:00 PM (in response to marx3)Correct me if I'm wrong but, if you don't want it to be an EJB, you can use:
@Startup(depends={"entityManager"})