Announcement Announcement Module
Collapse
No announcement yet.
Web and EJB classloader problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Web and EJB classloader problem

    I have an application that supports a business delegate EJB and MDBs. These components utilize beans created from an application context. A single root config xml file imports all files needed by these beans. A ClassPathXMLApplicationContext is contructed, passing in this root config file. The xml files and the associated beans are deployed to the EJB classloader. This all works fine and as expected.

    I encountered issues however when adding a web application. I'm using echo2 as the gui framework for the Web and get the web application context from

    org.springframework.context.ApplicationContext context = WebApplicationContextUtils.getWebApplicationContex t(servletContext);

    The echo2 beans instantiate nicely from this context.

    I encountered a problem when referencing bean definintions deployed on the EJB classloader from the web application context. I wasn't really sure how to link the two different contexts in different classloaders, so I imported the root config XML file into the web application context xml file. Now all the web GUI components can see the required bean definitions.

    Well, there surfaced yet another problem when implementing an editor used for changing bean values instantiated by Spring. The beans are defined as a singleton; but I am getting two instead of one instance. It looks like the Web based editor is editing the instance that is created in the web classloader; but the process that consumes the bean, which requires the changes, uses an instance in the EJB classloader.

    I've tried a few things to try as resolve this but to no avail. I'm not sure where to go from here. I don't see a way to programatically join the two contexts after they are instantiated and the EJB context doesn't know about the web context when it gets intantiated, so I don't think heiarchical context can be used.

    I've seen some related problems logged on this site; but the solution for my case wasn't clear to me. I'm relatively new to Spring...

    Any assistance would be greatly appreciated.

    I've tried looking at the locator; but still not sure how to join the two contexts. I also thought about deploying everything on the EJB classloader and using a singleton to access the Echo2 beans from within the web tier; but that seems like a violation of the web / ejb boundaries. I would like to keep the two seperated....

    Any suggestions?

  • #2
    I don't think it can be done the way you described. You cannot "join" the two applicationcontexts.

    To access the beans (EJB's MDB's) from the webapplication context you will have to do an old fashioned JNDI lookup. Ofcourse spring has some nice features for this. You want to checkout section 17.1 of the reference manual.

    Code:
    <bean id="myComponent"
     class="org.springframework.ejb.access.SimpleRemoteStatelessSessionProxyFactoryBean ">
      <property name="jndiName" value="myComponentjndiName"/>
      <property name="businessInterface" value="com.mycom.MyComponent"/>
    </bean>
    where myComponentjndiName is the name of the EJB and com.mycom.MyComponent is the interface defining all the business methods.

    Comment


    • #3
      I'm not actually using Spring for the EJB. Using a good old fashion serivce locator. I'll do that later, but don't think this is related to my problem.

      I want to dependency inject beans defined and deployed in the EJB classloader into the beans defined in the web classloader, essentially bypassing the EJB.

      The EJB uses spring beans for its business logic and the web app uses Spring beans in the web tier that have dependencies on the beans in the ejb tier.

      Comment


      • #4
        I don't know for sure but it could be possible if the ejb.jar and web.war where in the same ear, then putting the shared classes in a seperate jar, put it on the classpath using the meta-inf files in the ejb.jar and web.war then it could work.

        Comment


        • #5
          Well, maybe this isn't a classloader issue after all. I thought is might be.

          It must have been constructing multiple ApplicationContexts instead. I looked into the ContextSingletonBeanFactoryLocator closer, implemented it, and the problem was solved. I looked at this before, but didn't quite get it right...

          Thanks for your help...

          Comment

          Working...
          X