Spring is kind of mighty to use just for some initialization parameters; however, using Spring for dependency injection provides greatly improved management of object dependencies for the rest of your app.
My current app is a Spring / Struts 2 app running on Tomcat. Here is a quick overview of how I'm using Spring with Struts 2 -- I will address your specific question after the basics below. In my Spring configuration file (applicationContext.xml), I have all my various beans wired together, including my Struts actions. So, for instance, I have a UserDetailsService bean that has a reference to my UserDao, and a UserDetailsAction that has a reference to the UserDetailsService: <bean id="userDao" class="com.bogus.dao.UserDaoImpl"/> <bean id="userDetailsService" class="com.bogus.service.UserDetailsServiceImpl"> <property name="userDao" ref="userDao"/> </bean> <bean id="userDetailsAction" class="com.bogus.action.UserDetailsAction"> <property name="userDetailsService" ref="userDetailsService"/> </bean> Then, in struts.xml, I don't have a direct reference to my UserDetailsAction class -- instead I have a reference to the Spring-managed bean: <action name="userDetail" class="userDetailAction" method="input"> <result name="success" type="redirect-action">userList</result> <result name="input">/WEB-INF/secure/admin/userDetail.jsp</result> </action> Now -- as to your specific question. If your database connections are handled by an object of a specific class, you can use Spring to inject the necessary values into your database connector object. Something like this: <bean id="databaseConnector" class="com.bogus.db.Connector"> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost/" /> <property name="username" value="dbUser" /> <property name="password" value="password" /> </bean> This is actually not ideal if you're going to be migrating this application through various environments. Better than this would be to set up a context file in each environment and refer to it in your Spring configuration. But if you're in the early dev stages, this works well. jk On Fri, May 16, 2008 at 8:49 AM, <[EMAIL PROTECTED]> wrote: > Hi Jim, > > could you detail on this? I am not really familiar with Spring and at first > sight it looks much too mighty for just some little initialization, but > maybe its providing the hook I am looking for. > > Martin > > > ----- Original Nachricht ---- > Von: Jim Kiley <[EMAIL PROTECTED]> > An: Struts Users Mailing List <user@struts.apache.org> > Datum: 16.05.2008 14:30 > Betreff: Re: [struts2]how to configure the web app > > > Hi Martin, > > > > This seems like an ideal situation for using Spring dependency injection. > > Are you familiar with Spring at all? > > > > jk > > > > On Fri, May 16, 2008 at 8:04 AM, <[EMAIL PROTECTED]> wrote: > > > > > Hi, > > > > > > I am new to Struts2 and stumbling immediately. > > > > > > I want to have an initialization routine in my web app which will > connect > > > to a data base etc. at startup time. This routine needs some parameters > > (e. > > > g. the path of a config file to be read). How can I access such > external > > > information? > > > > > > With Servlets I would normally implement a ServletContextListener which > > > would get its information as an init-param from web.xml. > > > But for Struts2 there is no <servlet> spec where I could put it. > > > > > > Writing Struts1 applications I typically utilized a plugin which could > > read > > > parameters from struts-config.xml. Maybe this is still possible, but > the > > > Struts2 plugin mechanism seems to be too powerful (or just > overwhelming) > > for > > > me. > > > > > > What is the preferred way? > > > > > > Thanks > > > > > > Martin > > > > > > --------------------------------------------------------------------- > > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > > > > > -- > > Jim Kiley > > Technical Consultant | Summa > > [p] 412.258.3346 [m] 412.445.1729 > > http://www.summa-tech.com > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- Jim Kiley Technical Consultant | Summa [p] 412.258.3346 [m] 412.445.1729 http://www.summa-tech.com