Announcement Announcement Module
Collapse
No announcement yet.
How to pass web-based bean to non-spring object Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to pass web-based bean to non-spring object

    Hi,

    We have a problem that hopefully somebody can help with.
    Basically we are developing a web-based application using Spring,
    and use the standard ContextListener for setting up the application context.

    Part of our application is a SAML library that we use for single-sign-on,
    where the library does its own object instantiation which is something that
    we can't change. So right now we have a need to pass a bean from our
    aplication context to an object that is not managed by Spring.

    What is the best way to do it?

    We thought of using SingleBeanFactoryLocator, but not sure how to use it in
    relation to the appication context currently being loaded by ContextListener.

    Any insight is greatly appreciated.

    -DJ

  • #2
    Originally posted by wirianto
    Hi,

    We have a problem that hopefully somebody can help with.
    Basically we are developing a web-based application using Spring,
    and use the standard ContextListener for setting up the application context.

    Part of our application is a SAML library that we use for single-sign-on,
    where the library does its own object instantiation which is something that
    we can't change. So right now we have a need to pass a bean from our
    aplication context to an object that is not managed by Spring.
    If you wouln`t use Spring, how does that bean get the reference? Do you have to inject it into some kind of factory method/constructor? Or do you have to set it afterwards?

    There are many solution to deal with non spring-managed beans, but it depends on the situation which one you need. So I need more information.

    Comment


    • #3
      Originally posted by wirianto
      Hi,

      We thought of using SingleBeanFactoryLocator, but not sure how to use it in
      relation to the appication context currently being loaded by ContextListener.

      Any insight is greatly appreciated.

      -DJ
      You _could_ use ContextSingletonBeanFactoryLocator. The standard ContextLoader/ContextLoaderListener mechanism to load a web-app's application context at the well known location (bound to the ServeletContext) has built-in support for loading a shared (via ContextSingletonBeanFactoryLocator) parent context to that. So you would have to put the beans you need to access for the SAML sign on, in the shared parent context, not the child one loaded by the ContextLoader.

      Regards,

      Comment


      • #4
        Are there any examples on how to use ContextSingletonBeanFactoryLocator programmatically with context that is loaded using ContextLoaderListener.

        Our web.xml has the following declaration:
        <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml,/WEB-INF/action-servlet.xml,/WEB-INF/sso-protocol.xml,/WEB-INF/sso-security.xml</param-value>
        </context-param>

        <listener>
        <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
        </listener>

        For using the ContextSingletonBeanFactoryLocator, do I still have to declared beanRefContext.xml? If I do, does the following is the right way to do it:
        <?xml version="1.0" encoding="UTF-8" ?>
        <!DOCTYPE beans (View Source for full doctype...)>
        <beans default-lazy-init="false" default-dependency-check="none" default-autowire="no">
        <bean id="ssos" class="org.springframework.context.support.XmlWebA pplicationContext" abstract="false" singleton="true" lazy-init="default" autowire="default" dependency-check="default">
        <constructor-arg>
        <list>
        <value>/WEB-INF/applicationContext.xml</value>
        <value>/WEB-INF/action-servlet.xml</value>
        <value>/WEB-INF/sso-protocol.xml</value>
        <value>/WEB-INF/sso-security.xml</value>
        </list>
        </constructor-arg>
        </bean>
        </beans>

        Thanks,
        -Wirianto

        Comment


        • #5
          Your basic approach is right, but the contents of your beanRefContext.xml file is wrong. It doesn't make sense for it to have the same stuff in there as in the child web-app context, to which it's supposed to be a parent...

          You need to split up your bean definitions between the two of them, treating the shared one as the middle-tier definitons. Any beans in the child, web-app context can still be injected with beans from the parent, which is loaded first.

          Comment

          Working...
          X