Announcement Announcement Module
Collapse
No announcement yet.
Wiring together web and non-web application contexts... Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Wiring together web and non-web application contexts...

    Hi:
    I am new to Spring and am trying to figure how to setup my application contexts.

    I plan to have the following application contexts:
    1.) GlobalServices app context for services that are used by any component in the system. Typically, these servcies would setup listeners for events, start timers, and provide some business servces to web/non-web clients - I would prefer to load this context as an MBean in my Jboss server, or something similar.
    2.) Web app contexts which interact with the GlobalServices context to execute business logic, get models, etc.. There can pontentially be several web contexts (which are peers of each other). The web contexts are defined as usual under WEB-INF/*-servlet.xml format.

    Question:
    1.) How do my webapp based contexts refer to beans in GlobalServices context?
    2.) Is there a way to inject services defined in GlobalServices into the *-servlet.xml controller beans?
    3.) I have looked at SingletonBeanFactoryLocator, but it doesnot seem it will solve the problem of integrating war + non-war based app contexts. Or maybe I didnot read it right.

    -Thanks in advance.
    -Inder.

  • #2
    The main problem when working with webapp-non-webapp applications is that you have multiple classloaders that you have to share information across. SingletonBeanFactoryLocator contains the principle but since singletons are per classloader it will not work in your configuration.
    The most usual workaround is to publish the main context (GlobalServices as you call them) inside JNDI in a well known location from where each webapp can retrieve it. This solution is also portable across most application servers.

    Comment


    • #3
      Thanks costin.

      I was planning to do something similar after reading and thinking some more on this subject. Basically I am going to have a GlobalServicesLookup bean that is capable of looking up any GlobalServices. This bean will be defined in the applicationContext of all webapps, and injected into all my controllers or other clients of these services.

      Thanks
      Inder.

      Comment


      • #4
        Originally posted by indercoder
        Thanks costin.

        I was planning to do something similar after reading and thinking some more on this subject. Basically I am going to have a GlobalServicesLookup bean that is capable of looking up any GlobalServices. This bean will be defined in the applicationContext of all webapps, and injected into all my controllers or other clients of these services.

        Thanks
        Inder.
        What I'm doing is this. My applications typically look like this:

        Code:
          my-app.ear
            + my-app-core.sar
            + my-app-frontend.war
            + my-app-backend.war
        I deploy in JBoss, so I wrapped my Spring code in a Service Archive that publishes the Spring application context to JNDI. The jboss-service.xml looks like this:

        Code:
        <server>
          <mbean code="com.example.SpringApplicationContext" name="my.app:service=SpringApplicationContext">
            <depends>jboss.jca:name=MyDS,service=DataSourceBinding</depends>
            <attribute name="Configuration">classpath:META-INF/spring-context.xml</attribute>
          </mbean>
        </server>
        Then, the web applications use a JMXContextLoaderServlet and their own spring context definition. The only thing this servlet does extra is to get the JNDI name of the parent application context from the servlet config:

        Code:
          <context-param>
            <param-name>contextParentName</param-name>
            <param-value>my.app:service=SpringApplicationContext</param-value>
          </context-param>
        and then use that when creating the web app's spring context.

        Works pretty well. I know JBoss now has their own Spring deployer, but this setup gives me a bit more control. For example wrt dependend container services.

        S.

        Comment

        Working...
        X