Announcement Announcement Module
Collapse
No announcement yet.
context:component-scan Error Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • context:component-scan Error

    Hi all,

    I'm making use of the tag
    Code:
    <context:component-scan base-package="com.company.shared" />
    to scan through my classes for a @Controller annotation. My Controller with the @Controller annotation is located under the package com.company.shared.common. This Controller along with the other files is exposed as a dependent jar file which gets picked up my the web app (through dependency in pom.xml).

    While running this web app locally deployed to Tomcat starts and runs as expected. However deploying this web app to one of our unix boxes having Apache Geronimo server throws error during start itself. Following is the stack trace of the error:

    org.springframework.beans.factory.BeanDefinitionSt oreException: Failed to read candidate component class: URL [jar:file:..../webapp/WEB-INF/lib/feature-1.0.0.jar!/com/company/shared/action/DefaultAction.class]; nested exception is java.lang.IllegalArgumentException: Expected url [jar:file:..../webapp/WEB-INF/lib/feature-1.0.0.jar!/com/company/shared/], but was [jar:file:..../webapp//WEB-INF/lib/feature-1.0.0.jar!/com/company/shared/action/DefaultAction.class]
    at org.springframework.context.annotation.ClassPathSc anningCandidateComponentProvider.findCandidateComp onents(ClassPathScanningCandidateComponentProvider .java:237)
    at org.springframework.context.annotation.ClassPathBe anDefinitionScanner.doScan(ClassPathBeanDefinition Scanner.java:204)
    at org.springframework.context.annotation.ComponentSc anBeanDefinitionParser.parse(ComponentScanBeanDefi nitionParser.java:84)
    at org.springframework.beans.factory.xml.NamespaceHan dlerSupport.parse(NamespaceHandlerSupport.java:73)
    at org.springframework.beans.factory.xml.BeanDefiniti onParserDelegate.parseCustomElement(BeanDefinition ParserDelegate.java:1335)
    at org.springframework.beans.factory.xml.BeanDefiniti onParserDelegate.parseCustomElement(BeanDefinition ParserDelegate.java:1325)
    at org.springframework.beans.factory.xml.DefaultBeanD efinitionDocumentReader.parseBeanDefinitions(Defau ltBeanDefinitionDocumentReader.java:135)
    at org.springframework.beans.factory.xml.DefaultBeanD efinitionDocumentReader.registerBeanDefinitions(De faultBeanDefinitionDocumentReader.java:93)
    at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.registerBeanDefinitions(XmlBeanDefinit ionReader.java:493)
    at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.doLoadBeanDefinitions(XmlBeanDefinitio nReader.java:390)
    at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.loadBeanDefinitions(XmlBeanDefinitionR eader.java:334)
    at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.loadBeanDefinitions(XmlBeanDefinitionR eader.java:302)
    at org.springframework.beans.factory.support.Abstract BeanDefinitionReader.loadBeanDefinitions(AbstractB eanDefinitionReader.java:143)
    at org.springframework.beans.factory.support.Abstract BeanDefinitionReader.loadBeanDefinitions(AbstractB eanDefinitionReader.java:178)
    at org.springframework.beans.factory.support.Abstract BeanDefinitionReader.loadBeanDefinitions(AbstractB eanDefinitionReader.java:149)
    at org.springframework.web.context.support.XmlWebAppl icationContext.loadBeanDefinitions(XmlWebApplicati onContext.java:124)
    at org.springframework.web.context.support.XmlWebAppl icationContext.loadBeanDefinitions(XmlWebApplicati onContext.java:93)
    at org.springframework.context.support.AbstractRefres hableApplicationContext.refreshBeanFactory(Abstrac tRefreshableApplicationContext.java:130)
    at org.springframework.context.support.AbstractApplic ationContext.obtainFreshBeanFactory(AbstractApplic ationContext.java:467)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:397)
    at com.company.ContextLoader.createWebApplicationCont ext(WebFrameworkContextLoader.java:44)
    at org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:197)
    .........

    Caused by: java.lang.IllegalArgumentException: Expected url [jar:file:..../webapp/WEB-INF/lib/feature-1.0.0.jar!/com/company/shared/], but was [jar:file:..../webapp/WEB-INF/lib/feature-1.0.0.jar!/com/company/shared/action/DefaultAction.class]
    at org.apache.geronimo.kernel.classloader.JarFileUrlS treamHandler.openConnection(JarFileUrlStreamHandle r.java:63)
    at java.net.URL.openConnection(URL.java:957)
    at org.springframework.core.io.UrlResource.getInputSt ream(UrlResource.java:121)
    at org.springframework.core.type.classreading.SimpleM etadataReader.<init>(SimpleMetadataReader.java:45)
    at org.springframework.core.type.classreading.SimpleM etadataReaderFactory.getMetadataReader(SimpleMetad ataReaderFactory.java:80)
    at org.springframework.core.type.classreading.Caching MetadataReaderFactory.getMetadataReader(CachingMet adataReaderFactory.java:101)
    at org.springframework.context.annotation.ClassPathSc anningCandidateComponentProvider.findCandidateComp onents(ClassPathScanningCandidateComponentProvider .java:213)
    ... 90 more
    While running locally the file JarFileUrlStreamHandler was getting picked up form axis2-kernel jar, while in the unix box as from the error log above the JarFileUrlStreamHandler is picked from the geronimo-kernel jar.
    It looks like there a difference in the classloader mechanism between the two, although not sure why this is happening.

    Another interesting observation is that if were to have the codebase (which contains the Controller etc..) bundled as part of the web-app, it seems to work fine.

    Has anyone come across this before?

    Thanks.

  • #2
    context:component-scan Error

    Please let me know if more details needs to be added here..

    Comment

    Working...
    X