Announcement Announcement Module
No announcement yet.
ApplicationContext within jar Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • ApplicationContext within jar

    A jar-file implements a client as described here:

    public class ToolsClient {
       private ApplicationContext applicationContext;
       public ToolsClient( ApplicationContext parentContext ) {
          applicationContext = new ClassPathXmlApplicationContext(new String[]{"classpath:spring.xml"}, parentContext );
       public PropertyClient getPropertyClient() {
          return (PropertyClient) applicationContext.getBean("propertyClient");
    The client is invoked by specifying a parent context. The junit tests run fine, all seems to be good.
    But then i am using a second hibernate client. It supplies it's own spring.xml, which is different and independent from the tools spring.xml. This module instantiates the tools client, but when accesing getPropertyClient() spring throws a "no such bean exception". It seems the tool-client find the wrong spring.xml. Any idea?

  • #2
    I analzed the problem some more: spring searches the classpath and finds the spring.xml in an other jar. I am confused about this.
    In general a java classLoader tries to lookup in the current context, this may be a jar-file. If the resource is not found, to parent loader is used.
    Springs seems to breaks this mechanismn and always uses the classpath for searching. For a classpath context this may be okay, but a ClassLoaderApplicationContext is missing in the api.