Uploaded image for project: 'Spring XD'
  1. Spring XD
  2. XD-1994

ParentLastURLClassLoader should set itself as context ClassLoader

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Done
    • Priority: Major
    • Resolution: Complete
    • Affects Version/s: None
    • Fix Version/s: 1.0 GA
    • Component/s: Runtime
    • Labels:
      None
    • Story Points:
      4
    • Rank (Obsolete):
      1740
    • Sprint:
      Sprint 32

      Description

      I am converting a Spring XD Sample (Batch notifications) from copying jars to (old way)

      $XD_HOME/lib
      

      To rather copy the module jar to (new preferred way)

      $XD_HOME/modules/job/payment-import/lib
      

      By doing so, I hit a classloader issue. Custom classes and resources are loaded in Spring XD using org.springframework.xd.module.support.ParentLastURLClassLoader.

      However, the sample is initializing custom bean definitions and one of those creates a new DataSource using the EmbeddedDatabaseBuilder. This class however, under the hood, uses the Default class loader to load SQL scripts:

      	public DefaultResourceLoader() {
      		this.classLoader = ClassUtils.getDefaultClassLoader();
      	}
      

      Therefore, the SQL scripts are NOT FOUND.

      Possible Solution

      A possible solution seems to be for ParentLastURLClassLoader to set itself as the context ClassLoader for the current thread:

      	public ParentLastURLClassLoader(URL[] classpath, ClassLoader parent) {
      		...
      		Thread.currentThread().setContextClassLoader(this);
      		...
      	}
      

        Attachments

          Activity

            People

            Assignee:
            hillert Gunnar Hillert
            Reporter:
            hillert Gunnar Hillert
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: