1 2 3 4 Previous Next 59 Replies Latest reply: Nov 24, 2009 12:23 AM by Marius Bogoevici RSS

Spring Component Auto Detection

Zithulele Shange Newbie

Hi,

I am deploying my Spring application to JBoss AS 5. After a couple of days I managed to make it work with multiple contexts. The problem I encountered is that I can't auto detect my spring components. I traced it down to the new VFS used by deployers and JBoss AS 5. and the way the Spring util class is listing files. It only use 'File' protocol and then it finds 'vfsfile' protocol and then don't scan the directory as it considers it as non existent in the file system.

Where can I find the VFS spec?
The fix would be to extend the Spring path matcher to understand the 'vfsfile' protocol and list files on the directory.

  • 1. Re: Spring Component Auto Detection
    Ales Justin Master

    OK, this is not really the topic of this forum (see sticky), but since it's an interesting topic, and I (re)wrote most of VFS, I'll help you. :-)


    Where can I find the VFS spec?

    There is no spec.
    This is JBoss custom virtual-file-system.
    Try here:
    - http://wiki.jboss.org/wiki/JBoss5VirtualFileSystem
    - http://wiki.jboss.org/auth/wiki/JBoss5DeploymentFramework

    The idea of VFS is to be structure agnostic - no diff between 'walking' over directories/files and jars/entries.

    So besides vfsfile, there are vfszip and vfsjar protocols - used for (nested)*archive handling.
    vfszip is new impl of vfsjar, removing locking issues that we had on Windows.

    So, take a look, and if you have any questions, simply post here and I'll try to answer.

    btw: which Spring class is doing this?

  • 2. Re: Spring Component Auto Detection
    Zithulele Shange Newbie

    Thanks for the pointers.

    Here is the stack trace:

    2008-06-27 09:41:32,514 DEBUG [org.springframework.core.io.support.PathMatchingResourcePatternResolver] Cannot search for matching files underneath URL [vfsfile:/D:/server/jboss-5.0.0.Beta4/server/wits/deploy/wits-deployment-ear.ear/wits-wims-batch.jar/za/ac/wits/batch/] because it does not correspond to a directory in the file system
    java.io.FileNotFoundException: URL [vfsfile:/D:/server/jboss-5.0.0.Beta4/server/wits/deploy/wits-deployment-ear.ear/wits-wims-batch.jar/za/ac/wits/batch/] cannot be resolved to absolute file path because it does not reside in the file system: vfsfile:/D:/server/jboss-5.0.0.Beta4/server/wits/deploy/wits-deployment-ear.ear/wits-wims-batch.jar/za/ac/wits/batch/
    at org.springframework.util.ResourceUtils.getFile(ResourceUtils.java:198)
    at org.springframework.core.io.UrlResource.getFile(UrlResource.java:156)
    at org.springframework.core.io.support.PathMatchingResourcePatternResolver.doFindPathMatchingFileResources(PathMatchingResourcePatternResolver.java:495)
    at org.springframework.core.io.support.PathMatchingResourcePatternResolver.findPathMatchingResources(PathMatchingResourcePatternResolver.java:341)
    at org.springframework.core.io.support.PathMatchingResourcePatternResolver.getResources(PathMatchingResourcePatternResolver.java:262)
    at org.springframework.context.support.AbstractApplicationContext.getResources(AbstractApplicationContext.java:1019)
    at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:177)
    at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:200)
    at org.springframework.context.annotation.ComponentScanBeanDefinitionParser.parse(ComponentScanBeanDefinitionParser.java:84)
    at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:69)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1253)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1243)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:135)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:92)
    at org.jboss.spring.factory.NamedXmlBeanDefinitionReader.registerBeanDefinitions(NamedXmlBeanDefinitionReader.java:54)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:398)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.importBeanDefinitionResource(DefaultBeanDefinitionDocumentReader.java:190)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseDefaultElement(DefaultBeanDefinitionDocumentReader.java:147)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:132)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:92)
    at org.jboss.spring.factory.NamedXmlBeanDefinitionReader.registerBeanDefinitions(NamedXmlBeanDefinitionReader.java:54)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:398)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
    at org.jboss.spring.factory.NamedXmlApplicationContext.loadBeanDefinitions(NamedXmlApplicationContext.java:87)
    at org.jboss.spring.factory.NamedXmlApplicationContext.loadBeanDefinitions(NamedXmlApplicationContext.java:82)
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:123)
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:423)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:353)
    at org.jboss.spring.factory.NamedXmlApplicationContext.(NamedXmlApplicationContext.java:61)
    at org.jboss.spring.factory.NamedXmlApplicationContext.(NamedXmlApplicationContext.java:50)
    at org.jboss.spring.deployers.ApplicationContextDeployer$1.doCreate(ApplicationContextDeployer.java:41)
    at org.jboss.spring.deployers.ApplicationContextDeployer$1.doCreate(ApplicationContextDeployer.java:44)
    at org.jboss.spring.deployers.AbstractSpringMetaDataDeployer$SpringDeploymentVisitor.deploy(AbstractSpringMetaDataDeployer.java:72)
    at org.jboss.spring.deployers.AbstractSpringMetaDataDeployer$SpringDeploymentVisitor.deploy(AbstractSpringMetaDataDeployer.java:58)
    at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployerWithInput.internalDeploy(AbstractRealDeployerWithInput.java:108)
    at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:50)
    at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:169)
    at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:853)
    at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:906)
    at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:794)
    at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:327)
    at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1309)
    at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:734)
    at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:862)
    at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:784)
    at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:622)
    at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:411)
    at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:498)
    at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:506)
    at org.jboss.system.server.profileservice.ProfileServiceBootstrap.loadProfile(ProfileServiceBootstrap.java:246)
    at org.jboss.system.server.profileservice.ProfileServiceBootstrap.start(ProfileServiceBootstrap.java:131)
    at org.jboss.bootstrap.AbstractServerImpl.start(AbstractServerImpl.java:408)
    at org.jboss.Main.boot(Main.java:208)
    at org.jboss.Main$1.run(Main.java:534)
    at java.lang.Thread.run(Thread.java:619)

  • 3. Re: Spring Component Auto Detection
    Ales Justin Master

    I guess we'll be seeing a lot of these in new JBoss5. :-(
    Since not a lot of frameworks out there knows how to handle anything else besides plain JDK url/uri stuff, which is a shame.
    I already provided a patch for Facelets, so that our Seam could work.

    I suggest you go ahead, try how far you can go with fixing this with some vfs aware code. Or making that 'file' agnostic.
    If you got stuck, I'll help you.
    And then we can see what we should do with that:
    1) separate artifact bridging vfs&spring_component_lookup
    2) patch for spring :-)
    3) useful instructions for others

  • 4. Re: Spring Component Auto Detection
    Ales Justin Master

     

    "alesj" wrote:
    OK, this is not really the topic of this forum (see sticky), but since it's an interesting topic, and I (re)wrote most of VFS, I'll help you. :-)

     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:353)
    at org.jboss.spring.factory.NamedXmlApplicationContext.(NamedXmlApplicationContext.java:61)
    at org.jboss.spring.factory.NamedXmlApplicationContext.(NamedXmlApplicationContext.java:50)
    at org.jboss.spring.deployers.ApplicationContextDeployer$1.doCreate(ApplicationContextDeployer.java:41)
    at org.jboss.spring.deployers.ApplicationContextDeployer$1.doCreate(ApplicationContextDeployer.java:44)
    at org.jboss.spring.deployers.AbstractSpringMetaDataDeployer$SpringDeploymentVisitor.deploy(AbstractSpringMetaDataDeployer.java:72)
    at org.jboss.spring.deployers.AbstractSpringMetaDataDeployer$SpringDeploymentVisitor.deploy(AbstractSpringMetaDataDeployer.java:58)

    You should mention this.
    Now I feel like a smart ass. :-)

  • 5. Re: Spring Component Auto Detection
    Zithulele Shange Newbie

    Sorry for not mentioning that, I wanted to be short, but I missed the important part.

    I am looking at it, I will surely ask about what I will come up with as the fix.

  • 6. Re: Spring Component Auto Detection
    Ales Justin Master

     

    "zithuba" wrote:
    Sorry for not mentioning that, I wanted to be short, but I missed the important part.

    Nah, np, just kiddin'. :-)

    "zithuba" wrote:

    I am looking at it, I will surely ask about what I will come up with as the fix.

    I'm looking too.
    I already have a few ideas, but you go ahead.
    More heads know more ... or how they say. :-)

  • 7. Re: Spring Component Auto Detection
    Ales Justin Master

     

    "alesj" wrote:

    I'm looking too.
    I already have a few ideas, but you go ahead.

    OK, this is what I came up with:
    - http://anonsvn.jboss.org/repos/jbossas/trunk/spring-int/src/main/org/jboss/spring/io

    If you can pull this down, add the missing bit, in NamedXmlApplicationContext
     protected ResourcePatternResolver getResourcePatternResolver()
     {
     return new VFSResourcePatternResolver(getClassLoader());
     }
    

    Build it, test it. :-)

  • 8. Re: Spring Component Auto Detection
    Ales Justin Master

    Or, can you explain me what I need to do to create an example that is gonna use that?

  • 9. Re: Spring Component Auto Detection
    Ales Justin Master

     

    "alesj" wrote:
    Or, can you explain me what I need to do to create an example that is gonna use that?

    I've changed my Spring-deployer tests to use @Component scanning, and they pass. :-)

    I'll release new deployer right after JBoss5_CR1.
    But you can already build it yourself from the trunk.

  • 10. Re: Spring Component Auto Detection
    Zithulele Shange Newbie

    I get an error when building the classes, it is on the 'VFSResource.java' on the line with 'getCompatibleURL(file)' method call on VFSUtils. I was using the JBoss source I downloaded to compile.

    How can I build from the trunk and have all the dependencies?

    Or, can you explain me what I need to do to create an example that is gonna use that?


    I had a class annotated with @Component, that is an aspect for sending emails after the Job has finished running with a success or error. I wanted to use auto detection.



  • 11. Re: Spring Component Auto Detection
    Ales Justin Master

     

    "zithuba" wrote:

    How can I build from the trunk and have all the dependencies?

    It should work, otherwise I wouldn't commit - specially so close to CR1 release. ;-)

    Do a clean checkout.
    Go to build dir.
    Simply run 'build clean most'.
    This does everything, downloads all dependencies via maven2 (see component-matrix/pom.xml), builds AS instance.



  • 12. Re: Spring Component Auto Detection
    Zithulele Shange Newbie

     

    "alesj" wrote:

    It should work, otherwise I wouldn't commit - specially so close to CR1 release. ;-)


    It does work, but with prior versions of Spring. I am using 2.5.3 in JBoss AS CR1 and Spring has added a method called 'isReadable' in Resource. I have added the method in my local version and compiled and it is working. But I just returned true for all cases, as I don't have a full grasp of the VFS.

    Thanks for the great work.

  • 13. Re: Spring Component Auto Detection
    Ales Justin Master

    I updated the trunk to use 2.5.5.
    And I added this

     public boolean isReadable()
     {
     try
     {
     return file.getSize() > 0;
     }
     catch (IOException e)
     {
     throw new RuntimeException(e);
     }
     }
    

    instead of plain true.

    Can you try it out?

  • 14. Re: Spring Component Auto Detection
    Zithulele Shange Newbie

    Hi There again,

    I am trying to deploy a jar with the spring beans and I get this error:

    Caused by: java.lang.IllegalArgumentException: Cannot find entry: java.io.FileInputStream@37f44d, za/ac/wits/batch/aop
    at org.jboss.virtual.plugins.context.zip.ZipEntryContext.findEntry(ZipEntryContext.java:338)
    at org.jboss.virtual.plugins.context.zip.ZipEntryContext.createZipSource(ZipEntryContext.java:284)
    at org.jboss.virtual.plugins.context.zip.ZipEntryContext.init(ZipEntryContext.java:214)
    at org.jboss.virtual.plugins.context.zip.ZipEntryContext.(ZipEntryContext.java:145)
    at org.jboss.virtual.plugins.context.zip.ZipEntryContext.(ZipEntryContext.java:130)
    at org.jboss.virtual.plugins.context.zip.ZipEntryContextFactory.getVFS(ZipEntryContextFactory.java:71)
    at org.jboss.virtual.VFS.getVFS(VFS.java:135)
    at org.jboss.virtual.VFS.getRoot(VFS.java:149)
    at org.jboss.spring.io.VFSResourcePatternResolver.getVFSResources(VFSResourcePatternResolver.java:85)
    at org.jboss.spring.io.VFSResourcePatternResolver.findPathMatchingResources(VFSResourcePatternResolver.java:69)
    at org.springframework.core.io.support.PathMatchingResourcePatternResolver.getResources(PathMatchingResourcePatternResolver.java:262)
    at org.springframework.context.support.AbstractApplicationContext.getResources(AbstractApplicationContext.java:1019)
    at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:177)
    at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:200)
    at org.springframework.context.annotation.ComponentScanBeanDefinitionParser.parse(ComponentScanBeanDefinitionParser.java:84)
    at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:69)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1253)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1243)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:135)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:92)
    at org.jboss.spring.factory.NamedXmlBeanDefinitionReader.registerBeanDefinitions(NamedXmlBeanDefinitionReader.java:52)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:398)

    If I deploy the same jar inside an ear file it works fine.

    Thanks.

1 2 3 4 Previous Next