• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Spring in Web Application - How can I get the application context from a Java class

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, I am still a bit new to Spring but I am hoping someone can clear this up for me.

I am running a web application with Spring and I can get the application context from a servlet no problem using:

However I would like to also get the context on the business side (Model) without depending on servlets.

In my web/xml I have:

I also have


Any help is very welcome, thanks

Regards,
 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Bart,

Since you already have the context, would you have a problem in caching the "context path" value in a variable or some form of a constant/hash-map and access that in your beans or business service layer. I don't think that did be difficult if you are not changing that variable/path - which in spring MVC/servlets - you will never need to!
On the other hand is there a trouble that I am not seeing in as to why you cannot cache the context path in a "String" and access it later where-ever you need?
Other things you can do is have a bean conveniently encapsulate the ApplicationContext and pass it down your call heirarchy into the business layer as a parameter.

Regards,
 
Bart Stanz
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, I took the latter approach and it worked out fine.

Regards
reply
    Bookmark Topic Watch Topic
  • New Topic