将Play框架从2.5.x升级到2.6.x时如何解决依赖注入 [英] How to fix dependency injection when upgrading play framework from 2.5.x to 2.6.x Scala

查看:138
本文介绍了将Play框架从2.5.x升级到2.6.x时如何解决依赖注入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试从play 2.5.x升级到2.6.3. (因为2.5.x不支持WS中的多部分内容.import play.api.libs.ws.DefaultBodyWritables._引发异常.官方文档中的代码示例不起作用.编译器需要Body Writables,而Body Writables则不直到2.6.x为止

I am trying to upgrade from play 2.5.x to 2.6.3. (Because 2.5.x doesn't support multipart post in WS. import play.api.libs.ws.DefaultBodyWritables._ throws Exceptions. The code example in the official document doesn't work. The compiler needs the Body Writables which is not provided until 2.6.x)

因此,我将plugin.sbt版本更改为2.6.3,并将sbt升级为0.13.15.并编辑build.sbt文件以添加guice和json.该项目编译良好.但是,当我开始运行sbt并访问 http://localhost:9000 时,它抛出了一系列与我在本地lib/目录中有一个jar文件.相同的代码在2.5.x下也可以正常工作.

So I changed the plugin.sbt version to 2.6.3 and upgraded sbt to 0.13.15. And edit the build.sbt file to add guice and json. The project compiles fine. But when I started with sbt run, and visit http://localhost:9000, it throws a bunch of Exception related to a jar file I have in the local lib/ directory. The same code worked just fine with 2.5.x.

例外:

1)注入构造函数java.lang.NoClassDefFoundError时出错:com/google/common/util/concurrent/FutureFallback 在db.ConcreteGGDB.(ConcreteGGDB.scala:24) 在Module.configure(Module.scala:29)处(通过模块:com.google.inject.util.Modules $ OverrideModule->模块) 定位db.ConcreteGGDB时

1) Error injecting constructor, java.lang.NoClassDefFoundError: com/google/common/util/concurrent/FutureFallback at db.ConcreteGGDB.(ConcreteGGDB.scala:24) at Module.configure(Module.scala:29) (via modules: com.google.inject.util.Modules$OverrideModule -> Module) while locating db.ConcreteGGDB

是否知道与本地jar相关的版本与2.6.x不兼容?还是我需要更改一些代码以进行依赖注入,而不是在Module.scala文件中指定?谢谢.

Any idea if this is related to the local jar is not compatible with 2.6.x? or I need to change some code to do dependency injection other than specify in the Module.scala file? Thanks.

推荐答案

为什么我会在Java中收到NoClassDefFoundError?

错误注入构造函数java.lang.NoClassDefFoundError:com/twitter/finagle/http/Method $ Get $

NoClassDefFound意味着您的代码需要一个类,但是 它找不到.通常在您的项目中发生 可传递地依赖于库的多个版本.为了 例如,假设您正在构建依赖于lib的项目A X和项目B,后者也依赖于libX.但是,项目B是 基于以前有一个类的旧版lib X构建的, 但它不再出口了.

NoClassDefFound means that there's a class that your code needs, but it can't find it. This typically happens when your project transitively depends on more than one version of a library. For example, imagine that you're building project A, which depends on lib X, and project B, which also depends on lib X. However, project B was built against an older version of lib X, which used to have a class, but which it no longer exports.

A => B => X(版本1)

A => B => X (version 1)

A => X(版本2)

A => X (version 2)

然后,当它运行时,A向B发出呼叫,B尝试发出呼叫 进入X,但是因为该项目现在使用的是更新版本,而不是 较旧的版本,找不到所需的类.

Then when it runs, A makes a call into B, which tries to make a call into X, but because the project now uses the newer version instead of the older version, it can't find the class it needs.

我鼓励您使用sbt-dependency-graph查看哪个 您依赖的[库名称]的版本,并确保 您使用的每个库都使用相同版本的[库名].

I would encourage you to use sbt-dependency-graph to see which versions of [library name] you're depending on transitively, and ensure that every library you use uses the same version of [library name].

看起来像本地jar的问题.

Looks like an issue with the local jar.

这篇关于将Play框架从2.5.x升级到2.6.x时如何解决依赖注入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆