Playframework独立作业连接到数据库两次

时间:2012-10-14 10:49:06

标签: playframework playframework-2.0

我在Play 2.0.4中有一个独立的工作,我想在Heroku上运行,如https://github.com/jamesward/play2-scheduled-job-demo中所述 我就像在样本中一样启动应用程序:

public class QueueWorker {
    public static void main(String[] args) {
        Application application = new Application(new File(args[0]), QueueWorker.class.getClassLoader(), null, Mode.Dev());
        Play.start(application);
    }
}

但是现在,从日志来看,Play由于某种原因连接到数据库两次,而EhCache第二次失败,因为它的名称已经注册:

[[37minfo[0m] play - database [default] connected at jdbc:mysql://localhost/myproject?characterEncoding=UTF-8
[[37minfo[0m] play - database [default] connected at jdbc:mysql://localhost/myproject?characterEncoding=UTF-8
Exception in thread "main" net.sf.ehcache.ObjectExistsException: Cache play already exists
    at net.sf.ehcache.CacheManager.addCache(CacheManager.java:990)
    at play.api.cache.EhCachePlugin.x$3(Cache.scala:111)
    at play.api.cache.EhCachePlugin.cache(Cache.scala:109)
    at play.api.cache.EhCachePlugin.onStart(Cache.scala:127)
    at play.api.Play$$anonfun$start$1.apply(Play.scala:60)
    at play.api.Play$$anonfun$start$1.apply(Play.scala:60)
    at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
    at scala.collection.immutable.List.foreach(List.scala:45)
    at play.api.Play$.start(Play.scala:60)
    at play.api.Play.start(Play.scala)
    at jobs.QueueWorker.main(QueueWorker.java:32)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

有趣的是,当我使用“play run”命令启动项目时,这不会发生。有没有人告诉我这可能是什么,或者我如何调试它来自哪里?

1 个答案:

答案 0 :(得分:0)

事实证明问题在于play-authenticate模块。即使你从play.plugins中删除所有条目并让它放在你的依赖项中,它也会产生这种错误。我在https://github.com/joscha/play-authenticate/issues/23创建了一个错误报告,希望很快就会修复。