Hello,
In my project I'm using file as Resource. I'm injecting it from src/main/resources and all work fine while I'm running project via gradle bootRun, mvn spring-boot:run or using idea. but as soon I'm building and packaging application using gradle or maven and running it as simple executable jar I'm always facing with that ussie:
error (gradle jar)
Caused by: java.io.FileNotFoundException: class path resource [schema.graphqls] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/Users/mak/Documents/code/test/spring/boot-graphql/build/libs/boot-graphql-0.0.2.jar!/BOOT-INF/classes!/schema.graphqls
i verified that required file is exists incide jars
unzip -l target/*.jar | grep schema.graphqls
271 11-12-2017 21:19 BOOT-INF/classes/schema.graphqls
unzip -l build/libs/*.jar | grep schema.graphqls
271 11-12-2017 21:19 BOOT-INF/classes/schema.graphqls
so it should be accessible on runtime here:
@Value("classpath:/schema.graphqls")
lateinit var schemaResource: Resource
question: can anybody explain me what I'm doing wrong and how can I fixed that?
note 1: here is a similar issue I've created on ratpack project - groovy template engine in same way is not accessible to template from bundled jar. Seems like Issue is very same
note 2: I'm facing with that issue in few latest projects I'm coding right now using Kotlin and Spring Boot 1.5.8.RELEASE...
Thanks for any help!
full stacktrace (maven jar)
2017-11-12 21:20:13.256 ERROR 84164 --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'queryRestResource' defined in URL [jar:file:/Users/mak/Documents/code/test/spring/boot-graphql/target/boot-grathql-0.0.3.jar!/BOOT-INF/classes!/daggerok/graphql/QueryRestResource.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'graphQL' defined in class path resource [daggerok/graphql/GraphQLConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [graphql.GraphQL]: Factory method 'graphQL' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'graphQLSchema' defined in class path resource [daggerok/graphql/GraphQLConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [graphql.schema.GraphQLSchema]: Factory method 'graphQLSchema' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'registry' defined in class path resource [daggerok/graphql/GraphQLConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [graphql.schema.idl.TypeDefinitionRegistry]: Factory method 'registry' threw exception; nested exception is java.io.FileNotFoundException: class path resource [schema.graphqls] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/Users/mak/Documents/code/test/spring/boot-graphql/target/boot-grathql-0.0.3.jar!/BOOT-INF/classes!/schema.graphqls
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:189) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1193) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1095) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.8.RELEASE.jar!/:1.5.8.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.8.RELEASE.jar!/:1.5.8.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.8.RELEASE.jar!/:1.5.8.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.8.RELEASE.jar!/:1.5.8.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.8.RELEASE.jar!/:1.5.8.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.8.RELEASE.jar!/:1.5.8.RELEASE]
at daggerok.BootGraphQLApplicationKt.main(BootGraphQLApplication.kt:10) [classes!/:0.0.3]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_152]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_152]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_152]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_152]
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [boot-grathql-0.0.3.jar:0.0.3]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [boot-grathql-0.0.3.jar:0.0.3]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [boot-grathql-0.0.3.jar:0.0.3]
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) [boot-grathql-0.0.3.jar:0.0.3]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'graphQL' defined in class path resource [daggerok/graphql/GraphQLConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [graphql.GraphQL]: Factory method 'graphQL' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'graphQLSchema' defined in class path resource [daggerok/graphql/GraphQLConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [graphql.schema.GraphQLSchema]: Factory method 'graphQLSchema' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'registry' defined in class path resource [daggerok/graphql/GraphQLConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [graphql.schema.idl.TypeDefinitionRegistry]: Factory method 'registry' threw exception; nested exception is java.io.FileNotFoundException: class path resource [schema.graphqls] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/Users/mak/Documents/code/test/spring/boot-graphql/target/boot-grathql-0.0.3.jar!/BOOT-INF/classes!/schema.graphqls
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:835) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
... 27 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [graphql.GraphQL]: Factory method 'graphQL' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'graphQLSchema' defined in class path resource [daggerok/graphql/GraphQLConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [graphql.schema.GraphQLSchema]: Factory method 'graphQLSchema' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'registry' defined in class path resource [daggerok/graphql/GraphQLConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [graphql.schema.idl.TypeDefinitionRegistry]: Factory method 'registry' threw exception; nested exception is java.io.FileNotFoundException: class path resource [schema.graphqls] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/Users/mak/Documents/code/test/spring/boot-graphql/target/boot-grathql-0.0.3.jar!/BOOT-INF/classes!/schema.graphqls
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
... 40 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'graphQLSchema' defined in class path resource [daggerok/graphql/GraphQLConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [graphql.schema.GraphQLSchema]: Factory method 'graphQLSchema' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'registry' defined in class path resource [daggerok/graphql/GraphQLConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [graphql.schema.idl.TypeDefinitionRegistry]: Factory method 'registry' threw exception; nested exception is java.io.FileNotFoundException: class path resource [schema.graphqls] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/Users/mak/Documents/code/test/spring/boot-graphql/target/boot-grathql-0.0.3.jar!/BOOT-INF/classes!/schema.graphqls
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.obtainBeanInstanceFromFactory(ConfigurationClassEnhancer.java:389) ~[spring-context-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:361) ~[spring-context-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at daggerok.graphql.GraphQLConfig$$EnhancerBySpringCGLIB$$3182a09a.graphQLSchema(<generated>) ~[classes!/:0.0.3]
at daggerok.graphql.GraphQLConfig.graphQL(GraphQLConfig.kt:41) ~[classes!/:0.0.3]
at daggerok.graphql.GraphQLConfig$$EnhancerBySpringCGLIB$$3182a09a.CGLIB$graphQL$1(<generated>) ~[classes!/:0.0.3]
at daggerok.graphql.GraphQLConfig$$EnhancerBySpringCGLIB$$3182a09a$$FastClassBySpringCGLIB$$80c78f2a.invoke(<generated>) ~[classes!/:0.0.3]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358) ~[spring-context-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at daggerok.graphql.GraphQLConfig$$EnhancerBySpringCGLIB$$3182a09a.graphQL(<generated>) ~[classes!/:0.0.3]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_152]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_152]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_152]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_152]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
... 41 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [graphql.schema.GraphQLSchema]: Factory method 'graphQLSchema' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'registry' defined in class path resource [daggerok/graphql/GraphQLConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [graphql.schema.idl.TypeDefinitionRegistry]: Factory method 'registry' threw exception; nested exception is java.io.FileNotFoundException: class path resource [schema.graphqls] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/Users/mak/Documents/code/test/spring/boot-graphql/target/boot-grathql-0.0.3.jar!/BOOT-INF/classes!/schema.graphqls
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
... 63 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'registry' defined in class path resource [daggerok/graphql/GraphQLConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [graphql.schema.idl.TypeDefinitionRegistry]: Factory method 'registry' threw exception; nested exception is java.io.FileNotFoundException: class path resource [schema.graphqls] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/Users/mak/Documents/code/test/spring/boot-graphql/target/boot-grathql-0.0.3.jar!/BOOT-INF/classes!/schema.graphqls
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.obtainBeanInstanceFromFactory(ConfigurationClassEnhancer.java:389) ~[spring-context-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:361) ~[spring-context-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at daggerok.graphql.GraphQLConfig$$EnhancerBySpringCGLIB$$3182a09a.registry(<generated>) ~[classes!/:0.0.3]
at daggerok.graphql.GraphQLConfig.graphQLSchema(GraphQLConfig.kt:37) ~[classes!/:0.0.3]
at daggerok.graphql.GraphQLConfig$$EnhancerBySpringCGLIB$$3182a09a.CGLIB$graphQLSchema$5(<generated>) ~[classes!/:0.0.3]
at daggerok.graphql.GraphQLConfig$$EnhancerBySpringCGLIB$$3182a09a$$FastClassBySpringCGLIB$$80c78f2a.invoke(<generated>) ~[classes!/:0.0.3]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358) ~[spring-context-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at daggerok.graphql.GraphQLConfig$$EnhancerBySpringCGLIB$$3182a09a.graphQLSchema(<generated>) ~[classes!/:0.0.3]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_152]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_152]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_152]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_152]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
... 64 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [graphql.schema.idl.TypeDefinitionRegistry]: Factory method 'registry' threw exception; nested exception is java.io.FileNotFoundException: class path resource [schema.graphqls] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/Users/mak/Documents/code/test/spring/boot-graphql/target/boot-grathql-0.0.3.jar!/BOOT-INF/classes!/schema.graphqls
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
... 86 common frames omitted
Caused by: java.io.FileNotFoundException: class path resource [schema.graphqls] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/Users/mak/Documents/code/test/spring/boot-graphql/target/boot-grathql-0.0.3.jar!/BOOT-INF/classes!/schema.graphqls
at org.springframework.util.ResourceUtils.getFile(ResourceUtils.java:215) ~[spring-core-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.core.io.AbstractFileResolvingResource.getFile(AbstractFileResolvingResource.java:53) ~[spring-core-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at daggerok.graphql.GraphQLConfig.registry(GraphQLConfig.kt:22) ~[classes!/:0.0.3]
at daggerok.graphql.GraphQLConfig$$EnhancerBySpringCGLIB$$3182a09a.CGLIB$registry$0(<generated>) ~[classes!/:0.0.3]
at daggerok.graphql.GraphQLConfig$$EnhancerBySpringCGLIB$$3182a09a$$FastClassBySpringCGLIB$$80c78f2a.invoke(<generated>) ~[classes!/:0.0.3]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358) ~[spring-context-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at daggerok.graphql.GraphQLConfig$$EnhancerBySpringCGLIB$$3182a09a.registry(<generated>) ~[classes!/:0.0.3]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_152]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_152]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_152]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_152]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
... 87 common frames omitted
Regards, Maksim
Comment From: wilkinsona
Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.
Rather than assuming the resource is a file, you should read it using an input stream.
Comment From: daggerok
hello, @wilkinsona
thank you for pointing me into input stream!
worked solution is coming with that repo project fix commit:
val resource = resources.getResource("classpath:schema.graphqls")
InputStreamReader(resource.inputStream).use {
return SchemaParser().parse(it.readText())
}
where resources is injected org.springframework.core.io.ResourceLoader
Regards
Comment From: saeedansari
Hi @daggerok ,
I have different problem which is passing a directory path to another component in my application . The directory is inside my resources directory, so it is part of classpath. But inside the jar, the absolute path looks like
/Users/saeed/projects/my-application/target/my-application-1.0-SNAPSHOT.jar!/BOOT-INF/classes!/q2
and passing above path does not seem to work.
By the way, I am also using spring boot.
I appreciate any help.
Comment From: oneone1995
@saeedansari hi, i got this error too..do you now tht reason know
Comment From: daggerok
@saeedansari, if needed folder path is: ./src/main/resources/g2, try use resources path with: classpath:/q2
Comment From: deepeshiworld
If you try to use resource.getFile() you will receive an error because Spring tries to access a file system path, but it can not access a path in your JAR.
Courtesy - https://smarterco.de/java-load-file-from-classpath-in-spring-boot/
Comment From: Pasupathi-Rajamanickam
I was in a need to get URL of resource to send that to another package and it was failing as classes! as part of URL. After so much time found this was helpful
URL url = new URL("classpath:/sam.wsdl");
Comment From: wedsa5
for anyone who finds themselves here, the InputStream is the correct answer. doing Resource.getFile() is the problem. Also see answer here