On 2/22/07, Wesley Wannemacher <[EMAIL PROTECTED]> wrote:
I looked for something similar a while back and didn't find anything simple. There are servlet context listeners (but that isn't really struts-2-ish).
I would strongly disagree that ServletContextListeners are "not really struts-2-ish". They are probably the best way to do any one-time initialization for an application, unless there's already some other code to do what you need... On 2/22/07, bob <[EMAIL PROTECTED]> wrote:
I could be wrong, but perhaps you should use the Spring IoC container for this. I can't point you to the correct documentation off hand, but I believe that this is the way to maintain a resource such as what you had previoulsy done with the Servlet's init method and the factory class. Maybe someone with more experience integrating spring and struts2 can chime in with some doc recommendations. I'm a bit of a newbie myself unfortunatley.
I don't think you have to use the Spring IoC container for this, but I think it's probably a pretty good way to do it. I am extremely fond of using Spring to establish an application context (not to be confused with the webapp "application context") and letting most of my code be blissfully ignorant of how things get set up. This page is the place to start on using the Spring plugin with Struts 2: http://struts.apache.org/2.x/docs/spring-plugin.html In short, Spring can instantiate any beans you want, either as singletons or as "prototypes" (that is, a new bean is instantiated each time it is called for from the Spring app context). In instantiating, it can also satisfy dependencies automagically. In the Struts2/Spring model, this is usually applied to action classes, which would be instantiated by Spring when requested by Struts. Spring would just give you an Action instance with a reference to your factory (although once you start digging in Spring, you might find that you can even hide the Factory and keep your Actions super simple and flexible.) Joe -- Joe Germuska [EMAIL PROTECTED] * http://blog.germuska.com "The truth is that we learned from João forever to be out of tune." -- Caetano Veloso