Spring Framework
  1. Spring Framework
  2. SPR-3815

<context:component-scan> Classloader problem

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: 2.1 M3, 2.1 M4
    • Fix Version/s: None
    • Component/s: Core
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      I've tried to use <context:component-scan> in a web application which depends on some local component (.jar) that contains some classes registered into Spring Container using @Component annotation.

      However those classes are not found by ClassPathBeanDefinitionScanner class although t the base-package property is set up corretly. It is problably an issue with PathMatchingResourcePatternResolver as can be figure out in the testcase attached.

      The full description of the problem and an use case is described at spring core forum:
      http://forum.springframework.org/showthread.php?t=43234

        Activity

        Hide
        Mark Fisher added a comment -

        Ok - it looks like I jumped to a conclusion with regards to 'Extension-Name'. I was just emulating another jar that I had been testing against successfully.

        I am actually able to get the test case to pass by simply unpacking and recreating the JAR:
        jar xf springmoduletest.jar
        jar cf newjar.jar bizservices

        So... it has nothing to do with 'Extension-Name' (sorry). My current MANIFEST.MF looks like this:
        Manifest-Version: 1.0
        Created-By: 1.5.0_07 (Apple Computer, Inc.)

        ...and the test passes.

        I have investigated the existing JAR to see what might be the problem but yet to discover what it is.

        Mark

        Show
        Mark Fisher added a comment - Ok - it looks like I jumped to a conclusion with regards to 'Extension-Name'. I was just emulating another jar that I had been testing against successfully. I am actually able to get the test case to pass by simply unpacking and recreating the JAR: jar xf springmoduletest.jar jar cf newjar.jar bizservices So... it has nothing to do with 'Extension-Name' (sorry). My current MANIFEST.MF looks like this: Manifest-Version: 1.0 Created-By: 1.5.0_07 (Apple Computer, Inc.) ...and the test passes. I have investigated the existing JAR to see what might be the problem but yet to discover what it is. Mark
        Hide
        Leonardo Pinho added a comment -

        Yeah, I guess the problem is not related to Manifest.mf because I get the manifest.mf from the original jar and generated it again using winzip and it worked.

        So I guess it is a issue with jar generation from Eclipse because I built the orginal jar using it and I did the same generation again and the test case failed.

        Therefore I think you can close this bug because it is not related to Spring and it is a very specific problem.

        Thank you very much for your help!!

        Regards,
        Leonardo

        Show
        Leonardo Pinho added a comment - Yeah, I guess the problem is not related to Manifest.mf because I get the manifest.mf from the original jar and generated it again using winzip and it worked. So I guess it is a issue with jar generation from Eclipse because I built the orginal jar using it and I did the same generation again and the test case failed. Therefore I think you can close this bug because it is not related to Spring and it is a very specific problem. Thank you very much for your help!! Regards, Leonardo
        Hide
        Mark Fisher added a comment -

        Leonardo,

        Thanks for that information. I must admit that I don't typically export JAR files from within eclipse but rather just command-line 'jar'. So, I did try it out and had the same results as you (the JAR exported by Eclipse caused my TestCase to fail).

        However, I then discovered that the Export->"Java"->"JAR file" wizard has some 'options' at the bottom, and one of the checkboxes (unchecked by default) is "Add directory entries". If you make sure to select that option, then the Eclipse-exported JAR file will also work with getResource("packagename")... and therefore it will also work with Spring's path-matching and the ant-path wildcards of your original example.

        Mark

        Show
        Mark Fisher added a comment - Leonardo, Thanks for that information. I must admit that I don't typically export JAR files from within eclipse but rather just command-line 'jar'. So, I did try it out and had the same results as you (the JAR exported by Eclipse caused my TestCase to fail). However, I then discovered that the Export->"Java"->"JAR file" wizard has some 'options' at the bottom, and one of the checkboxes (unchecked by default) is "Add directory entries". If you make sure to select that option, then the Eclipse-exported JAR file will also work with getResource("packagename")... and therefore it will also work with Spring's path-matching and the ant-path wildcards of your original example. Mark
        Hide
        Mark Fisher added a comment -

        This pretty much summarizes the difference. Notice that the second JAR (created with "Add directory entries" selected) actually contains directories in addition to the classes:

        jar tf springmoduletest.jar
        META-INF/MANIFEST.MF
        bizservices/springmoduletest/core/MyModuleManager.class
        bizservices/springmoduletest/core/OtherModuleManager.class
        bizservices/springmoduletest/core/impl/OtherModuleManagerImpl.class
        bizservices/springmoduletest/core/impl/MyModuleManagerImpl.class

        jar tf springmoduletest-with-directories.jar
        META-INF/
        META-INF/MANIFEST.MF
        bizservices/
        bizservices/springmoduletest/
        bizservices/springmoduletest/core/
        bizservices/springmoduletest/core/impl/
        bizservices/springmoduletest/core/impl/MyModuleManagerImpl.class
        bizservices/springmoduletest/core/impl/OtherModuleManagerImpl.class
        bizservices/springmoduletest/core/MyModuleManager.class
        bizservices/springmoduletest/core/OtherModuleManager.class

        Show
        Mark Fisher added a comment - This pretty much summarizes the difference. Notice that the second JAR (created with "Add directory entries" selected) actually contains directories in addition to the classes: jar tf springmoduletest.jar META-INF/MANIFEST.MF bizservices/springmoduletest/core/MyModuleManager.class bizservices/springmoduletest/core/OtherModuleManager.class bizservices/springmoduletest/core/impl/OtherModuleManagerImpl.class bizservices/springmoduletest/core/impl/MyModuleManagerImpl.class jar tf springmoduletest-with-directories.jar META-INF/ META-INF/MANIFEST.MF bizservices/ bizservices/springmoduletest/ bizservices/springmoduletest/core/ bizservices/springmoduletest/core/impl/ bizservices/springmoduletest/core/impl/MyModuleManagerImpl.class bizservices/springmoduletest/core/impl/OtherModuleManagerImpl.class bizservices/springmoduletest/core/MyModuleManager.class bizservices/springmoduletest/core/OtherModuleManager.class
        Hide
        Radha Spencer added a comment -

        Thank you very much for your research and post. I have been stumped for the past day and a half on this issue. Much appreciation.

        Show
        Radha Spencer added a comment - Thank you very much for your research and post. I have been stumped for the past day and a half on this issue. Much appreciation.

          People

          • Assignee:
            Mark Fisher
            Reporter:
            Leonardo Pinho
            Last updater:
            Trevor Marshall
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Days since last comment:
              3 years, 12 weeks, 3 days ago