问题 1:我使用 play 2.1.1 创建了一个示例 java 应用程序,并在应用程序启动时启动了调度程序。我做了一个播放编译然后播放开始,但我收到以下错误,如果我在这里做错了什么,请告诉我:
(Starting server. Type Ctrl+D to exit logs, the server will remain in background)
Play server process ID is 6160
@6edl861on: Cannot init the Global objectOops, cannot start the server.
at play.api.WithDefaultGlobal$$anonfun$play$api$WithDefaultGlobal$$globalInstance$1.apply(Application.scala:57)
at play.api.WithDefaultGlobal$$anonfun$play$api$WithDefaultGlobal$$globalInstance$1.apply(Application.scala:51)
at play.utils.Threads$.withContextClassLoader(Threads.scala:18)
at play.api.WithDefaultGlobal$class.play$api$WithDefaultGlobal$$globalInstance(Application.scala:50)
at play.api.DefaultApplication.play$api$WithDefaultGlobal$$globalInstance$lzycompute(Application.scala:383)
at play.api.DefaultApplication.play$api$WithDefaultGlobal$$globalInstance(Application.scala:383)
at play.api.WithDefaultGlobal$class.global(Application.scala:66)
at play.api.DefaultApplication.global(Application.scala:383)
at play.api.WithDefaultConfiguration$class.play$api$WithDefaultConfiguration$$fullConfiguration(Application.scala:80)
at play.api.DefaultApplication.play$api$WithDefaultConfiguration$$fullConfiguration$lzycompute(Application.scala:383)
at play.api.DefaultApplication.play$api$WithDefaultConfiguration$$fullConfiguration(Application.scala:383)
at play.api.WithDefaultConfiguration$class.configuration(Application.scala:82)
at play.api.DefaultApplication.configuration(Application.scala:383)
at play.api.Application$class.$init$(Application.scala:268)
at play.api.DefaultApplication.<init>(Application.scala:383)
at play.core.StaticApplication.<init>(ApplicationProvider.scala:52)
at play.core.server.NettyServer$.createServer(NettyServer.scala:228)
at play.core.server.NettyServer$$anonfun$main$5.apply(NettyServer.scala:259)
at play.core.server.NettyServer$$anonfun$main$5.apply(NettyServer.scala:258)
at scala.Option.map(Option.scala:145)
at play.core.server.NettyServer$.main(NettyServer.scala:258)
at play.core.server.NettyServer.main(NettyServer.scala)
Caused by: java.lang.RuntimeException: There is no started application
at scala.sys.package$.error(package.scala:27)
at play.api.Play$$anonfun$current$1.apply(Play.scala:46)
at play.api.Play$$anonfun$current$1.apply(Play.scala:46)
at scala.Option.getOrElse(Option.scala:120)
at play.api.Play$.current(Play.scala:46)
at play.api.Play.current(Play.scala)
at play.libs.Akka.system(Akka.java:25)
at Global.<init>(Global.java:27)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at play.api.WithDefaultGlobal$class.play$api$WithDefaultGlobal$$javaGlobal(Application.scala:30)
at play.api.DefaultApplication.play$api$WithDefaultGlobal$$javaGlobal$lzycompute(Application.scala:383)
at play.api.DefaultApplication.play$api$WithDefaultGlobal$$javaGlobal(Application.scala:383)
at play.api.WithDefaultGlobal$$anonfun$play$api$WithDefaultGlobal$$globalInstance$1.apply(Application.scala:52)
资源:
Global.java - 在应用程序/
public class Global extends GlobalSettings {
private Logger.ALogger log = Logger.of(Global.class);
private ActorRef myActor = Akka.system().actorOf(
new Props(Retreiver.class));
@Override
public void onStart(Application app) {
log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
Akka.system()
.scheduler()
.schedule(Duration.create(0, TimeUnit.MILLISECONDS),
Duration.create(10, TimeUnit.SECONDS), myActor, "tick",
Akka.system().dispatcher());
}
}
检索器.java:
public class Retreiver extends UntypedActor {
private Logger.ALogger log = Logger.of(TweetsRetreiver.class);
@Override
public void onReceive(Object arg0) throws Exception {
// some code here
}
}
应用程序.conf:
application.global=Global
问题 2:此外,在控制台或 Application.log 文件中都没有打印任何日志。我使用 play.Logger 包进行日志记录,这是用于登录 play 2.1.1 的正确包吗?请为此提供一个示例。
谢谢。