• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

getWebApplicationContext() w/ Struts

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm starting to integrate Spring into one of my Struts applications. I'm using the Spring/Struts Plugin and used ActionSupport to extend my Struts action class. I wire the Service Bean in the application context xml file. From the struts action class i use the getWebApplicaitonContext() to get the bean. My problem is that in the Service Bean I need to get a DAO bean. Right now I'm just creating a new ApplicationContext to get the DAO bean. Is there a better way to do this then have to create a new ApplicaitonContext each time?

I just started with Spring, so be nice!

Thanks,
Alan
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you'll want to do is wire up the DAO and Service so that your DAO is injected into the Service via a setter method. A very simplistic example might be:



And your service class might look like:

 
Stinging nettles are edible. But I really want to see you try to eat this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic