2017-05-21 76 views
0

我正在使用Java Play 2.5和EBeans,並希望在eclipse中運行我的UnitTests。如果我使用sbt test命令一切工作正常,但在Eclipse中我得到eclipse:使用Java Play進行JUnit測試Ebeans

Configuration error: Configuration error[Cannot register class [models.persistent.User] in Ebean server] 
    at play.api.Configuration$.configError(Configuration.scala:155) 
    at play.api.Configuration.reportError(Configuration.scala:808) 
    at play.Configuration.reportError(Configuration.java:368) 
    at play.db.ebean.DefaultEbeanConfig$EbeanConfigParser.addModelClassesToServerConfig(DefaultEbeanConfig.java:107) 
    at play.db.ebean.DefaultEbeanConfig$EbeanConfigParser.parse(DefaultEbeanConfig.java:82) 
    at play.db.ebean.DefaultEbeanConfig$EbeanConfigParser.get(DefaultEbeanConfig.java:56) 
    at play.db.ebean.DefaultEbeanConfig$EbeanConfigParser.get(DefaultEbeanConfig.java:40) 
    at com.google.inject.internal.ProviderInternalFactory.provision(ProviderInternalFactory.java:81) 
    at com.google.inject.internal.BoundProviderFactory.provision(BoundProviderFactory.java:72) 
    at com.google.inject.internal.ProviderInternalFactory.circularGet(ProviderInternalFactory.java:61) 
    at com.google.inject.internal.BoundProviderFactory.get(BoundProviderFactory.java:62) 
    at com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:46) 
    at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1103) 
    at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40) 
    at com.google.inject.internal.SingletonScope$1.get(SingletonScope.java:145) 
    at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:41) 
    at com.google.inject.internal.SingleParameterInjector.inject(SingleParameterInjector.java:38) 
    at com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterInjector.java:62) 
    at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:104) 
    at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85) 
    at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:267) 
    at com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:46) 
    at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1103) 
    at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40) 
    at com.google.inject.internal.SingletonScope$1.get(SingletonScope.java:145) 
    at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:41) 
    at com.google.inject.internal.FactoryProxy.get(FactoryProxy.java:56) 
    at com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:46) 
    at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1103) 
    at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40) 
    at com.google.inject.internal.SingletonScope$1.get(SingletonScope.java:145) 
    at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:41) 
    at com.google.inject.internal.InjectorImpl$2$1.call(InjectorImpl.java:1016) 
    at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1103) 
    at com.google.inject.internal.InjectorImpl$2.get(InjectorImpl.java:1012) 
    at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1051) 
    at play.api.inject.guice.GuiceInjector.instanceOf(GuiceInjectorBuilder.scala:405) 
    at play.api.inject.guice.GuiceInjector.instanceOf(GuiceInjectorBuilder.scala:400) 
    at play.api.db.evolutions.ApplicationEvolutionsProvider.get$lzycompute(EvolutionsModule.scala:53) 
    at play.api.db.evolutions.ApplicationEvolutionsProvider.get(EvolutionsModule.scala:53) 
    at play.api.db.evolutions.ApplicationEvolutionsProvider.get(EvolutionsModule.scala:44) 
    at com.google.inject.internal.ProviderInternalFactory.provision(ProviderInternalFactory.java:81) 
    at com.google.inject.internal.BoundProviderFactory.provision(BoundProviderFactory.java:72) 
    at com.google.inject.internal.ProviderInternalFactory.circularGet(ProviderInternalFactory.java:61) 
    at com.google.inject.internal.BoundProviderFactory.get(BoundProviderFactory.java:62) 
    at com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:46) 
    at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1103) 
    at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40) 
    at com.google.inject.internal.SingletonScope$1.get(SingletonScope.java:145) 
    at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:41) 
    at com.google.inject.internal.InternalInjectorCreator$1.call(InternalInjectorCreator.java:205) 
    at com.google.inject.internal.InternalInjectorCreator$1.call(InternalInjectorCreator.java:199) 
    at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092) 
    at com.google.inject.internal.InternalInjectorCreator.loadEagerSingletons(InternalInjectorCreator.java:199) 
    at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:180) 
    at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:110) 
    at com.google.inject.Guice.createInjector(Guice.java:96) 
    at com.google.inject.Guice.createInjector(Guice.java:84) 
    at play.api.inject.guice.GuiceBuilder.injector(GuiceInjectorBuilder.scala:181) 
    at play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.scala:123) 
    at play.api.test.FakeApplication.<init>(Fakes.scala:209) 
    at play.test.FakeApplication.<init>(FakeApplication.java:51) 
    at play.test.FakeApplication.<init>(FakeApplication.java:69) 
    at play.test.Helpers.fakeApplication(Helpers.java:172) 
    at controllers.UserControllerTest.provideFakeApplication(UserControllerTest.java:34) 
    at play.test.WithApplication.provideApplication(WithApplication.java:33) 
    at play.test.WithApplication.startPlay(WithApplication.java:51) 
    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:498) 
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) 
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) 
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24) 
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) 
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) 
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) 
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) 
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) 
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) 
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) 
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363) 
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) 
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) 
Caused by: java.lang.NoClassDefFoundError: io/ebean/bean/EntityBean 
    at java.lang.ClassLoader.defineClass1(Native Method) 
    at java.lang.ClassLoader.defineClass(ClassLoader.java:763) 
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) 
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467) 
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73) 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368) 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) 
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) 
    at java.lang.Class.forName0(Native Method) 
    at java.lang.Class.forName(Class.java:348) 
    at play.db.ebean.DefaultEbeanConfig$EbeanConfigParser.addModelClassesToServerConfig(DefaultEbeanConfig.java:105) 
    ... 87 more 
Caused by: java.lang.ClassNotFoundException: io.ebean.bean.EntityBean 
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) 
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) 
    ... 102 more 

我不能弄清楚什麼是錯誤,或者我怎樣才能正確地添加EntityBean的到我的類路徑中。該項目配置了EBeanEnhancer 10.x和我的SBT插件看起來像這樣:

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.5.14") 
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "5.1.0") 
addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "3.0.0") 
addSbtPlugin("com.typesafe.sbt" % "sbt-play-enhancer" % "1.1.0") 

我找不到在Eclipse中的幫助設置此功能的...謝謝!說明

回答

0

也許是遲,但我有同樣的問題,下面是它爲我https://stackoverflow.com/a/46019157/4391948

工作作爲總結,你需要知道玩ebean版本堵漏,然後安裝相應的插件(它可以適用於ebean 4.x至7.x或10.x)。安裝完成後,您需要右鍵單擊該項目並轉至配置以啓用eBean增強器。

希望這會有所幫助。