繁体   English   中英

与默认的类加载器和PlayFramework自定义类加载器冲突

[英]Conflict with default classloader and PlayFramework custom classloader

我正在一个项目中,我们使用播放框架(播放1.2.5)以及基于Google GUICE的自定义应用程序模块。

我的代码中出现了当前异常:

play.exceptions.JavaExecutionException: loader constraint violation: when resolving method "mypackage.Runner.queueJob(Lmodels/Job;)V" the class loader (instance of play/classloading/ApplicationClassloader) of the current class, controllers/Jobs, and the class loader (instance of sun/misc/Launcher$AppClassLoader) for resolved class, mypackage/Runner, have different Class objects for the type models/Job used in the signature
    at play.mvc.ActionInvoker.invoke(ActionInvoker.java:237)
    at Invocation.HTTP Request(Play!)
Caused by: java.lang.LinkageError: loader constraint violation: when resolving method "mypackage.Runner.queueJob(Lmodels/Job;)V" the class loader (instance of play/classloading/ApplicationClassloader) of the current class, controllers/Job, and the class loader (instance of sun/misc/Launcher$AppClassLoader) for resolved class, mypackage/Runner, have different Class objects for the type models/Job used in the signature
    at controllers.Jobs.listJobs(Jobs.java:19)
    at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:557)
    at play.mvc.ActionInvoker.invoke(ActionInvoker.java:508)
    at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:484)
    at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:479)
    at play.mvc.ActionInvoker.invoke(ActionInvoker.java:161)
    ... 1 more

根据我目前的分析,看来问题似乎与源文件夹结构以及应用程序的初始化方式有关。

我有以下结构:

专案/应用程式/ {播放控制器与模型等}专案/ src / {我专案的实作业务逻辑的类别}

启动播放应用程序时,我还从“播放管理的应用程序类”之外的“ src”文件夹中启动了作业。 似乎发生的事情是,这些作业访问的模型和其他类此时已使用默认的类加载器加载,当我尝试从播放应用程序类(视图等)中使用它们时,出现此错误告诉我使用的类是通过不同的类加载器创建的,因此具有不同的签名。

因此,总而言之,默认的类加载器和播放类加载器都加载相同的类,并且根据我如何调用它们,我会因未匹配而出错。

通过将所有源文件都移到project / app / source文件夹中,我已经能够解决此问题,但我想将src文件夹与play application文件夹分开。

  1. 有人知道我的分析是否正确吗?
  2. 如果1.上的“是”,是否有一种配置播放的方法,不仅可以从app文件夹中加载类,还可以从我的src文件夹中加载类?

任何输入表示赞赏。

您可以尝试将“ src”文件夹添加到Play.javaPath列表中,以让Play编译并加载您的类。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM