我正在开发一个项目,在该项目中我们将基于自定义Google GUICE的应用程序模块与play framework(play-1.2.5)一起使用。与默认类加载器和PlayFramework自定义类加载器冲突
我得到当前的异常在我的代码:
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”文件夹中启动作业(来自播放托管应用程序类以外的作业)。看起来会发生的情况是,这些作业访问的模型和其他类此时会用默认的类加载器加载,当我尝试从播放应用程序类(视图等)使用这些时,我得到此错误告诉我所使用的类是使用不同的类加载器创建的,因此具有不同的签名。
因此总之,默认的类加载器和play类加载器加载相同的类,并根据我如何调用它们,我得到错误匹配的错误。
我已经能够通过简单地将我的所有源文件移动到项目/应用程序/源文件夹中解决此问题,但我希望将src文件夹与播放应用程序文件夹分开。
- 有人知道我的分析是否正确吗?
- 如果1.上的“是”,是否有配置播放的方法,不仅可以从app文件夹加载类,还可以从我的src文件夹加载类?
任何输入表示赞赏。