Results 1 to 2 of 2

Thread: Injecting dynamic dependencies unspecifiable in the config

  1. #1
    Join Date
    Aug 2005
    Location
    Virginia
    Posts
    2

    Default Injecting dynamic dependencies unspecifiable in the config

    Two part newbie question:

    I have a set of business logic beans dependent upon a Principal-like object stored in the HttpSession. When I'm retrieving the beans using Spring, I'll need to pass this object into Spring's BeanFactory somehow so it will return a bean applicable to my user's session context.

    1) Can this be done using AutowireCapableBeanFactory's applyBeanPropertyValues?

    2) If so, when I apply a Prinicpal-like object's properties, will I need to synchronize this process so if two different users request a business logic bean at the same time, the second user will have to wait until the first user's Principal object is applied and a business logic logic bean is returned to him before applying the second user's Principal?

  2. #2
    Join Date
    Aug 2005
    Location
    Virginia
    Posts
    2

    Default Possible Soluion

    I think I may have found a way to handle this while avoiding synchronization issues. If all of this is obvious to a non-noob, feel free to ignore me.

    For all of my business logic beans dependent upon a principal-like User object, I had them implement an interface

    Code:
    interface UserSpecificBean {
      setUser(User user);
    }
    Then, I created a BeanPostProcessor

    Code:
    class SessionAwarePostProcessor {
       public SessionAwarePostProcessor(HttpSession session) {
         ... get the User object from the session
       }
       public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof UserSpecificBean) {
          ((UserSpecificBean)bean).setUser(user);
        }    
        return bean;
      }
    }
    and registered it when obtaining my WebApplicationContext

    Code:
    ConfigurableWebApplicationContext context = 
          (ConfigurableWebApplicationContext)WebApplicationContextUtils
          .getRequiredWebApplicationContext(session.getServletContext());
    ConfigurableBeanFactory factory = 
            (ConfigurableBeanFactory)context.getBeanFactory();    
    factory.addBeanPostProcessor(new SessionAwarePostProcessor (session));
    This way, I'm injecting the User-dependency into each bean when I retrieve it instead of into the entire BeanFactory.

Similar Threads

  1. Injecting multiple dependencies (List or Set)
    By ryans in forum Container
    Replies: 2
    Last Post: Aug 19th, 2005, 12:50 PM
  2. Injecting non-spring dependencies
    By Dantu in forum Container
    Replies: 5
    Last Post: Aug 1st, 2005, 03:59 PM
  3. could not satisfy dependencies
    By springuser in forum Container
    Replies: 4
    Last Post: Apr 26th, 2005, 01:15 PM
  4. Replies: 1
    Last Post: Apr 25th, 2005, 07:37 PM
  5. Replies: 2
    Last Post: Oct 20th, 2004, 02:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •