Announcement Announcement Module
Collapse
No announcement yet.
ContextSingletonBeanFactoryLocator on Jboss Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ContextSingletonBeanFactoryLocator on Jboss

    Hi,

    I have problems using ContextSingletonBeanFactoryLocator and classloader issues
    with Jboss. I know it's totally Jboss related but i really need to find out why it doesn't work and maybe someone else has the answer. It's mainly a packaging issue.


    Actually,

    My application is packaged like this:

    myapp.ear
    --> spring.jar
    --> mysar.sar
    --> myjar.jar

    My sar performs initialization tasks and one of them is to initialize spring contexts with the following code:

    BeanFactoryLocator sbf = ContextSingletonBeanFactoryLocator.getInstance();
    BeanFactoryReference bf = sbf.useBeanFactory("common.context");
    The problems is that Spring the common.context bean is not found and i figured out why it's because Spring can not find the beanRefContext.xml file which holds the bean definition because it uses a wrong classloader

    I declared spring.jar and myjar.jar in application.xml as Java modules (ex: spring.jar)

    In mysar.sar i displayed information of the current classloader and here's what i get:


    Code:
    11:58:54,765 INFO  [DeployerListenerService] Current classloader = org.jboss.mx.
    loading.UnifiedClassLoader3@10d16b{ url=file:/D:/applications/jboss-4.0.
    5.GA/server/default/deploy/myapp.ear/ ,addedOrder=40}


    and if i execute the following code:

    Code:
    Enumeration<URL> resourcesEnum = this.getClass().getClassLoader().getResources("beanRefContext.xml");


    the classloader find the resource beanRefContext.xml which is packaged in myjar.jar. It works as expected.

    The problem is Spring library executes almost the same code in the PathMatchingResourcePatternResolver class it executes:
    Code:

    Code:
    Enumeration resourceUrls = getClassLoader().getResources(path);

    where path is "beanRefContext.xml"
    and the getClassLoader() returned in debug mode has a path attribute of:

    Code:
    /D:/applications/jboss-4.0.5.GA/server/default/conf/

    and therefore is unable to see the beanRefContext.xml file packaged in my ear.

    Note that i configured in my ear a loader repository :
    Code:

    Code:
      <loader-repository> 
          test.com:loader=myapp
    </loader-repository>

    I don't understand why the classloader retrieved in Spring is the one associated with the universalrepository3 ? and not the HeirarchicalLoaderRepository3 of my ear???

    I checked the CLASSPATH and my Jboss installation to see if there were Spring classes elsewhere and no the only Spring classes are in the spring.jar of myapp.ear.

    Please i need help.

  • #2
    More information

    I think the issue comes from the fact that Spring by default use the following piece of code to retrieve the classloader:

    Code:
    Thread.currentThread().getContextClassLoader();
    The problem is that on Jboss the classloader returned is the one of the server and has no visibility on the files in the ear file.

    Would there be a workaround for this ?
    Thanks in advance,
    bengali

    Comment


    • #3
      ApplicationContext instances mostly have a classLoader property you can set (inherited from DefaultResourceLoader). I'm not sure if it necessarily helps with ContextSingletonBeanfactoryLocator since it will be loading the context definitions with a DefaultResourceLoader that it creates for you. I would raise an issue in JIRA on this. Joris might have something to say as well (check out his blog on blog.interface21.com).

      Comment

      Working...
      X