abashev / vfs-s3

Amazon S3 driver for Apache commons-vfs (Virtual File System) project
Apache License 2.0
93 stars 50 forks source link

Multiple providers registered for URL scheme "s3" #32

Closed ptahchiev closed 9 years ago

ptahchiev commented 9 years ago

Hello,

I have a spring-boot project that uses org.reflections:

https://github.com/ronmamo/reflections/

It all works fine when I run the project with the maven plugin mvn spring-boot:run. However, when I produce a fat war file and run it with java -jar target/storefront.war I get the following exception:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'localFileStorageService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultFileSystemManager' defined in class path resource [com/nemesis/platform/config/PlatformCoreConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.commons.vfs2.FileSystemManager]: Factory method 'defaultFileSystemManager' threw exception; nested exception is org.apache.commons.vfs2.FileSystemException: Could not create a file system manager of class "org.apache.commons.vfs2.impl.StandardFileSystemManager".
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:308)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1120)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1044)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)
    at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:813)
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741)
    ... 39 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultFileSystemManager' defined in class path resource [com/nemesis/platform/config/PlatformCoreConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.commons.vfs2.FileSystemManager]: Factory method 'defaultFileSystemManager' threw exception; nested exception is org.apache.commons.vfs2.FileSystemException: Could not create a file system manager of class "org.apache.commons.vfs2.impl.StandardFileSystemManager".
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1119)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1014)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:461)
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:435)
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:559)
    at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:169)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:305)
    ... 51 more
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.commons.vfs2.FileSystemManager]: Factory method 'defaultFileSystemManager' threw exception; nested exception is org.apache.commons.vfs2.FileSystemException: Could not create a file system manager of class "org.apache.commons.vfs2.impl.StandardFileSystemManager".
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
    ... 65 more
Caused by: org.apache.commons.vfs2.FileSystemException: Could not create a file system manager of class "org.apache.commons.vfs2.impl.StandardFileSystemManager".
    at org.apache.commons.vfs2.VFS.createManager(VFS.java:89)
    at org.apache.commons.vfs2.VFS.getManager(VFS.java:52)
    at com.nemesis.platform.config.PlatformCoreConfig.defaultFileSystemManager(PlatformCoreConfig.java:150)
    at com.nemesis.platform.config.PlatformCoreConfig$$EnhancerBySpringCGLIB$$424fad06.CGLIB$defaultFileSystemManager$9(<generated>)
    at com.nemesis.platform.config.PlatformCoreConfig$$EnhancerBySpringCGLIB$$424fad06$$FastClassBySpringCGLIB$$2bf4a0e0.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309)
    at com.nemesis.platform.config.PlatformCoreConfig$$EnhancerBySpringCGLIB$$424fad06.defaultFileSystemManager(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
    ... 66 more
Caused by: org.apache.commons.vfs2.FileSystemException: Could not load VFS configuration from "jar:file:/tmp/tomcat.6453335118692475459.8112/work/Tomcat/localhost/storefront/WEB-INF/lib/vfs-s3-2.3.1.jar!/META-INF/vfs-providers.xml".
    at org.apache.commons.vfs2.impl.StandardFileSystemManager.configure(StandardFileSystemManager.java:194)
    at org.apache.commons.vfs2.impl.StandardFileSystemManager.configurePlugins(StandardFileSystemManager.java:148)
    at org.apache.commons.vfs2.impl.StandardFileSystemManager.init(StandardFileSystemManager.java:118)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.commons.vfs2.VFS.createManager(VFS.java:76)
    ... 78 more
Caused by: org.apache.commons.vfs2.FileSystemException: Multiple providers registered for URL scheme "s3".
    at org.apache.commons.vfs2.impl.DefaultFileSystemManager.addProvider(DefaultFileSystemManager.java:208)
    at org.apache.commons.vfs2.impl.StandardFileSystemManager.addProvider(StandardFileSystemManager.java:374)
    at org.apache.commons.vfs2.impl.StandardFileSystemManager.configure(StandardFileSystemManager.java:268)
    at org.apache.commons.vfs2.impl.StandardFileSystemManager.configure(StandardFileSystemManager.java:190)
    ... 85 more

I stopped with a breakpoint in DefaultFileSystemManager:addProvider and indeed the s3 is registered twice. This makes sense because it is declared twice in the vfs-providers.xml:

<?xml version="1.0" encoding="UTF-8"?>
<providers>
    <provider class-name="com.intridea.io.vfs.provider.s3.S3FileProvider">
        <scheme name="s3"/>
    </provider>
  <operationProvider class-name="com.intridea.io.vfs.provider.s3.operations.S3FileOperationsProvider">
    <scheme name="s3" />
  </operationProvider>
</providers>

And when I run it from the maven plugin it is only registered once! What is the difference between operationProvider and provider? Why running it from a war file registers both providers, and running it from the webapps folder registers only one? How can I avoid this exception?

abashev commented 9 years ago

It looks like you have two vfs-s3 jars inside repackaged application.

ptahchiev commented 9 years ago

That's what i thought - but no. Trust me - there's only one vfs-s3-2.3.1.jar jar in the WEB-INF/lib

abashev commented 9 years ago

Without your sources or jar file I can't reproduce this issue

ptahchiev commented 9 years ago

I finally made some progress. Seems like the reflections library adds a lot of URLs to the classpath and these are the URLs that are used when vfs-s3 is called:

jar:file:/home/petar/workspace/nemesis-archetype/storefront/target/storefront.war!/WEB-INF/lib/vfs-s3-2.3.1.jar!/META-INF/vfs-providers.xml
jar:file:/tmp/tomcat.3907334520961542595.8112/work/Tomcat/localhost/storefront/WEB-INF/lib/vfs-s3-2.3.1.jar!/META-INF/vfs-providers.xml

So it's the same jar, but is added twice.

abashev commented 9 years ago

So issue closed?

ptahchiev commented 9 years ago

Yes, sorry about this - the real problem is that I have 2 times the jar in the classpath.