Running Nomin Mapper under Eclipse cause NominException: Resource not found

江枫思渺然 提交于 2020-01-05 07:55:10

问题


I am using a Spring/Groovy application with Nomin as mapper. My Tests run fine on console after gradle build/test. Nomin finds the groovy resource file with the defined mapping. But I dont get it work in Eclipse/STS.

I defined a Utils class to get the Resource File Name:

class ResourceUtils {
    static def getMapperResource() {
        ClassPathResource.newInstance("coinmarketcap2coin.groovy").filename
    }
}

My Class using Nomin Mapper calls the constructor as:

def nomin = new Nomin(ResourceUtils.getMapperResource())

Stacktrace:

java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125) ~[spring-test-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:107) ~[spring-test-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:190) ~[spring-test-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:132) ~[spring-test-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:242) ~[spring-test-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:227) [spring-test-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289) [spring-test-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) [junit-4.12.jar:4.12]
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291) [spring-test-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:246) [spring-test-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97) [spring-test-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) [junit-4.12.jar:4.12]
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) [junit-4.12.jar:4.12]
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) [junit-4.12.jar:4.12]
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) [junit-4.12.jar:4.12]
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) [junit-4.12.jar:4.12]
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) [spring-test-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) [spring-test-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.junit.runners.ParentRunner.run(ParentRunner.java:363) [junit-4.12.jar:4.12]
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190) [spring-test-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) [.cp/:na]
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) [.cp/:na]
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538) [.cp/:na]
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760) [.cp/:na]
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460) [.cp/:na]
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206) [.cp/:na]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'coinMarketCapTransformerBean' defined in class path resource [net/hemisoft/ccm/repository/flow/_coinmarketcap.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [net.hemisoft.ccm.repository.CoinMarketCapTransformer]: Constructor threw exception; nested exception is org.nomin.core.NominException: Specified resource coinmarketcap2coin.groovy isn't found!
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1232) ~[spring-beans-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1131) ~[spring-beans-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) ~[spring-beans-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502) ~[spring-beans-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312) ~[spring-beans-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310) ~[spring-beans-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:758) ~[spring-beans-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868) ~[spring-context-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:751) ~[spring-boot-2.0.0.M7.jar:2.0.0.M7]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:387) ~[spring-boot-2.0.0.M7.jar:2.0.0.M7]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) ~[spring-boot-2.0.0.M7.jar:2.0.0.M7]
at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:138) ~[spring-boot-test-2.0.0.M7.jar:2.0.0.M7]
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) ~[spring-test-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117) ~[spring-test-5.0.2.RELEASE.jar:5.0.2.RELEASE]
... 25 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [net.hemisoft.ccm.repository.CoinMarketCapTransformer]: Constructor threw exception; nested exception is org.nomin.core.NominException: Specified resource coinmarketcap2coin.groovy isn't found!
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:175) ~[spring-beans-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87) ~[spring-beans-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1224) ~[spring-beans-5.0.2.RELEASE.jar:5.0.2.RELEASE]
... 41 common frames omitted
Caused by: org.nomin.core.NominException: Specified resource coinmarketcap2coin.groovy isn't found!
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_144]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_144]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_144]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_144]
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83) ~[groovy-2.5.0-beta-2.jar:2.5.0-beta-2]
at org.codehaus.groovy.reflection.CachedConstructor.doConstructorInvoke(CachedConstructor.java:77) ~[groovy-2.5.0-beta-2.jar:2.5.0-beta-2]
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrap.callConstructor(ConstructorSite.java:84) ~[groovy-2.5.0-beta-2.jar:2.5.0-beta-2]
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:247) ~[groovy-2.5.0-beta-2.jar:2.5.0-beta-2]
at org.nomin.core.ScriptLoader.loadResource(ScriptLoader.groovy:60) ~[nomin-1.1.4.jar:na]
at org.nomin.core.Nomin.parse(Nomin.java:128) ~[nomin-1.1.4.jar:na]
at org.nomin.core.Nomin.parse(Nomin.java:124) ~[nomin-1.1.4.jar:na]
at org.nomin.core.Nomin.<init>(Nomin.java:42) ~[nomin-1.1.4.jar:na]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_144]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_144]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_144]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_144]
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83) ~[groovy-2.5.0-beta-2.jar:2.5.0-beta-2]
at org.codehaus.groovy.reflection.CachedConstructor.doConstructorInvoke(CachedConstructor.java:77) ~[groovy-2.5.0-beta-2.jar:2.5.0-beta-2]
at org.codehaus.groovy.runtime.callsite.ConstructorSite.callConstructor(ConstructorSite.java:45) ~[groovy-2.5.0-beta-2.jar:2.5.0-beta-2]
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:247) ~[groovy-2.5.0-beta-2.jar:2.5.0-beta-2]
at net.hemisoft.ccm.repository.CoinMarketCapTransformer.<init>(CoinMarketCapTransformer.groovy:13) ~[bin/:na]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_144]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_144]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_144]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_144]
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163) ~[spring-beans-5.0.2.RELEASE.jar:5.0.2.RELEASE]
... 43 common frames omitted

The file coinmarketcap2coin.groovy is under src/main/resources. How do I have to implement the getMapperResource method that it works on both console and Eclipse?

UPDATE:

For me it seems to be a bug with Eclipse and Groovy-classes under src/main/resources path, e.g. in case using Nomin mapper.

As you see in the screenshot it puts my coinmarketcap2coin.groovy under default package. When I rename it as coinmarketcap2coin.groovymapper, then it doesnt show it more in the default package but directly under src/main/resources.

In that case it works on both, Eclipse and Console with gradle. I already tried to configure the classpath in Eclipse to exclude .groovy files in the resource folder, but always after Gradle/Clean on project, it makes it back again in the default package.

I tried an mini example with same constallation, but maven project, there I didnt have that problem ... So I dont know ... It works for me now, but it is a hack somehow ... if somebody had same problem and a clean solution I would really appreciate the know about it.

来源:https://stackoverflow.com/questions/48329112/running-nomin-mapper-under-eclipse-cause-nominexception-resource-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!