public ServerServiceCall logged(ServerServiceCall serviceCall) {
return HeaderServiceCall.compose(requestHeader -> {
System.out.println("Received " + requestHeader.method() + " " + requestHeader.uri());
return serviceCall;
});
}
我更改了实现以验证请求标头中的访问令牌,我发现在我的项目中使用多个模块中的相同实现而不是复制/粘贴是有用的 . 要做到这一点我:
在我的项目中创建了一个名为 common-tools 的模块
创建了一个名为AuthorizationService的服务及其实现
创建了一个CommunModule类并覆盖了 configure 方法
试图覆盖 Descriptor descriptor() 方法,但我无法使其编译,它总是无法编译这是方法:
@Override
default Descriptor descriptor() {
Descriptor descriptor = named("security").withCalls(
Service.call(this::logged)
).withAutoAcl(true);
return descriptor;
}
控制台输出:
no suitable method found for call(this::logged)
[ERROR] method com.lightbend.lagom.javadsl.api.Service.call(akka.japi.function.Creator>) is not applicable
[ERROR] (cannot infer type-variable(s) Request,Response
[ERROR] (actual and formal argument lists differ in length))
[ERROR] method com.lightbend.lagom.javadsl.api.Service.call(java.lang.reflect.Method) is not applicable
[ERROR] (cannot infer type-variable(s) Request,Response
[ERROR] (argument mismatch; java.lang.reflect.Method is not a functional interface))
[ERROR] method com.lightbend.lagom.javadsl.api.Service.call(com.lightbend.lagom.javadsl.api.Descriptor.CallId,java.lang.Object) is not applicable
[ERROR] (cannot infer type-variable(s) Request,Response
[ERROR] (actual and formal argument lists differ in length))