Announcement Announcement Module
Collapse
No announcement yet.
Singleton in-memory lookup and web Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Singleton in-memory lookup and web

    Hi there,

    I'm quite new to the Spring framework. I have a situation where I have a Spring application hosted in Tomcat. In the service layer I need a singleton which contains an in-memory lookup table. I will have web service (CXF) requests coming in which will need to access that lookup.

    I know I can mark the bean as singleton, but will Tomcat start a different ApplicationContext to service each new request?

    Can you guys recommend a different strategy for achieving something like this? The in-memory lookup will be a type of write-back cache, so I really need only one instance.

    Thank you in advance for any assistance

  • #2
    By default the Spring beans are singleton. So you can just declare that bean in your application context and inject it in the needed services. Of course, that singleton will have to be threadsafe ...

    Tell us if you need a more precise description ...

    Comment


    • #3
      Hi,

      Thanks. I just need to understand the way that a web container like TomCat instantiates a Spring application context. Is it per unique web service request?

      Comment


      • #4
        It depends on your configuration/code

        If you use the ContextLoaderListener to load your context there will be one context (the root context). For each DispatcherServlet also an applicationcontext instantiated at startup.

        Now if you have in your code something like new ApplicationContext(yourfiles) then you have a problem and indeed for each request an ApplicationContext will be instantiated.

        However that is all explained in the reference guide of spring...

        Comment


        • #5
          Originally posted by mdeinum View Post
          It depends on your configuration/code

          If you use the ContextLoaderListener to load your context there will be one context (the root context). For each DispatcherServlet also an applicationcontext instantiated at startup.

          Now if you have in your code something like new ApplicationContext(yourfiles) then you have a problem and indeed for each request an ApplicationContext will be instantiated.

          However that is all explained in the reference guide of spring...

          Thanks! That points me in the right direction - I will go read up a bit more.

          Comment

          Working...
          X