【发布时间】:2012-08-28 05:26:34
【问题描述】:
我正在开发一个项目,我们将播放框架 (play-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
根据我目前的分析,问题似乎与源文件夹结构以及应用程序的初始化方式有关。
我有以下结构:
project/app/{播放控制器和模型等} project/src/{我的项目特定类实现业务逻辑}
当启动播放应用程序时,我还会在我的“src”文件夹中启动作业(从播放管理的应用程序类之外)。似乎发生的情况是这些作业访问的模型和其他类此时使用默认的类加载器加载,当我尝试从播放应用程序类(视图等)中使用这些时,我收到这个错误告诉我使用的类是使用不同的类加载器创建的,因此具有不同的签名。
因此,总而言之,默认类加载器和播放类加载器都会加载相同的类,并且根据我调用它们的方式,我会收到未匹配的错误。
我已经能够通过简单地将我的所有源文件移动到 project/app/ 源文件夹中来解决这个问题,但我希望将 src 文件夹与播放应用程序文件夹分开。
- 有人知道我的分析是否正确吗?
- 如果在 1. 上选择“是”,有没有办法将播放配置为不仅从 app 文件夹加载类,还从我的 src 文件夹加载类?
感谢任何输入。
【问题讨论】:
标签: java playframework classloader guice playframework-1.x