You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Dave Newton <ne...@yahoo.com> on 2008/03/14 00:34:32 UTC

[OT] RE: How to initialize business service objects?

--- Frank Fischer <fr...@digitalnomads.ch> wrote:
> I just read a bit regarding Spring. As far as i understand its focus is on
> J2EE appllications. I guess for what i want to do in a first step (my
> simple chat app) it would be overkill to use Spring. Do i get that right?

Not really.

IMO Spring is a light-weight(-ish) alternative to "true" JEE apps (note that
it's JEE now, not J2EE :)

S2's Spring integration is lightweight to the point of near-invisibility,
particularly for simple setups. It's as easy as defining a bean in a Spring
configuration file and providing a setter in your S2 action. There are
several benefits to doing so, but that's something you can discover on your
own if you decide to explore Spring. This particular usage is called
"Inversion of Control" (IoC) or (my preference) "Dependency Injection" (DI).

> I just don't understand how can i get access to a BusinessServiceObject
> created in one of my Action classes from another Action class. Just by
> declaring it as static?

No, by keeping it in session or application scope.

I'd recommend getting at least a minimal handle on some basic web application
technology and terminology before jumping in *too* deep: S2, like many
frameworks, pretty much requires a basic understanding of the fundamentals.
Without it it's hard to even know what questions to ask sometimes, and will
make the whole process much easier.

> Second thing i don't understand is, when will action objects be intatiated
> in the application server? 

Actions are instantiated per-request.

> As far as i remember from the early days of
> servlet programming (when i had to do with this technology the last time)
> the servlets are intantiated upon the first request. In a normal Servlet
> based Web app i would have intiantiated BusinessServiceObjects in a filter
> and placed them to the ServletContext. So i could be sure it's instantiated
> before the first request arrives and i can get a reference to it from
> anywhere in my web app.  But with Struts i don't see how i could do so.

You *could* do it the exact same way: S2 doesn't replace what you know about
web applications, it supplements it.

That said, it's probably better to perform tasks like that in
ServletContextListener (don't quote me on that; I have a notoriously bad
memory for anything camelCased) or whatever it's called.

Dave


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org