我必须按需输入API。
为此,我有
1.创建一个演员,调度程序
2.在模块
中绑定actor和Scheduler
3.在application.conf文件
调度工作正常,但是现在我想将WSClient注入Actor,使用ws发送请求,将响应记录到数据库中。
在将WSClient注入Actor时出现问题。 {3}}
我所做的是:-
package controllers;
import akka.actor.UntypedActor;
import play.Logger;
import javax.inject.Inject;
import play.mvc.*;
import play.libs.ws.*;
import java.util.concurrent.CompletionStage;
public class CronActor extends UntypedActor{
@Override
public void onReceive(final Object message) throws Throwable {
Logger.info("Write your crone task or simply call your method here that perform your task"+message);
@Inject WSClient ws;
WSRequest request = ws.url("https://api.exchangeratesapi.io/latest?base=USD&symbols=SGD,INR");
WSRequest complexRequest = request.setHeader("Accept", "Application/json");
CompletionStage<WSResponse> responsePromise = complexRequest.get();
//WSRequest complexRequest = request.setQueryParameter("base", "paramValue");
Logger.info("response is"+responsePromise)
}
}
我正在关注错误:-
error: annotation type not applicable to this kind of declaration
[error] @Inject WSClient ws;
[error] ^
[error] (compile:compileIncremental) javac returned nonzero exit code
那么,如何在Playframework-2.5.x中将WSClient注入Actor中?