Announcement Announcement Module
Collapse
No announcement yet.
Access singleton map from spring service? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Access singleton map from spring service?

    I am implementing a spring service that needs to perform a lookup in a map that will be shared across the JVM. While I am thinking that I can just store this map as a static instance variable of the service, I am wondering if there is a more element way to acheiving my goal?

    Thanks.

  • #2
    Re: Access singleton map from spring service?

    Originally posted by rhodepc
    I am implementing a spring service that needs to perform a lookup in a map that will be shared across the JVM.
    If the service is created by Spring, I would inject the dependency into it. The advantage is that your service is created they way it should.

    So how do others get access to the map?
    -You could store the map in some kind of singleton. And you can use a MethodInvokingFactoryBean in the Spring context so the map can be injected into the service. Personally I don`t like this solution because the internals of that Service can be access by everyone.
    -Make use of the ContextSingletonBeanFactoryLocator. Now every object in your system (doesn`t have to be created by Spring) can access the ApplicationContext and retrieve the information.

    Question:
    Can they ask the Service for the information in the map? Does the service provide this functionality? If it does, they should ask the service and not the map.

    If you want a better solution, you have to give more information:
    what is in the map?
    what does the service do?
    and why does the service need the map?

    Comment


    • #3
      Only the one spring service will have access to the map.

      It shoulds like the ContextSingletonBeanFactoryLocator is the way to go. I will do some reading on it.

      To explain the big picture, the map is going to store the currently authenticated users in the system. I am going to use the key of the sso token to perform the lookup. The spring "SSOService" that I am writing is going to refer to this map with the key that is passed to it and return the user, if found.

      While I realise that there are a few SSO libraries for java out there, my main focus is on authorization, but you can't deal with authorization until you establish identity.

      Thanks.

      Comment

      Working...
      X