简体   繁体   English

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

[英]Conflict with default classloader and PlayFramework custom classloader

I am working on a project where we use play framework (play-1.2.5) together with a custom Google GUICE based application module. 我正在一个项目中,我们使用播放框架(播放1.2.5)以及基于Google GUICE的自定义应用程序模块。

I am getting the current exception in my code: 我的代码中出现了当前异常:

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

According to my current analysis it seems like the problem is related to the source folder structure and how the application is initialized. 根据我目前的分析,看来问题似乎与源文件夹结构以及应用程序的初始化方式有关。

I have the following structure: 我有以下结构:

project/app/{play controllers and models etc.} project/src/{my project specific classes implementing the business logic} 专案/应用程式/ {播放控制器与模型等}专案/ src / {我专案的实作业务逻辑的类别}

When starting the play application I also start up jobs in my "src" folder (from outside of the play managed application classes). 启动播放应用程序时,我还从“播放管理的应用程序类”之外的“ src”文件夹中启动了作业。 What seem to happen is that models and other classes accessed by these jobs gets loaded with the default class-loader at this time, and when I try to use these from the play application classes (the view etc.) I get this error telling me that the classes used are created with different class-loaders and therefore have different signatures. 似乎发生的事情是,这些作业访问的模型和其他类此时已使用默认的类加载器加载,当我尝试从播放应用程序类(视图等)中使用它们时,出现此错误告诉我使用的类是通过不同的类加载器创建的,因此具有不同的签名。

So in conclusion both the default class loader and the play class loader load the same classes and depending on how I invoke them I get errors for the miss-match. 因此,总而言之,默认的类加载器和播放类加载器都加载相同的类,并且根据我如何调用它们,我会因未匹配而出错。

I have been able to solve this by simply moving all my source files into the project/app/ source folder but I would like to keep the src folder separate from the play application folder. 通过将所有源文件都移到project / app / source文件夹中,我已经能够解决此问题,但我想将src文件夹与play application文件夹分开。

  1. Does anybody know if I am correct in my analysis? 有人知道我的分析是否正确吗?
  2. If "yes" on 1., is there a way to configure play to not only load classes from the app folder but also from my src folder? 如果1.上的“是”,是否有一种配置播放的方法,不仅可以从app文件夹中加载类,还可以从我的src文件夹中加载类?

Any input is appreciated. 任何输入表示赞赏。

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

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

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