Closed biyisi closed 1 year ago
服务端:com.example.demo_0313.service.UserService和UserServiceImpl 客户端:com.example.clientdemo.service.UserService和UserServiceImpl
我在客户端新建软件包,把类路径改为com.example.demo_0313.service.UserService和UserServiceImpl之后可以完成调用。 如果这边需要保证客户端和服务端包括路径在内UserService完全相同,这样是不是不太合理?还是有其他处理办法?
当我修改服务端的UserService代码添加@RequestMapping("/user")和@GetMapping后,启用客户端的rest调用,通过8777可以调用服务端getUser方法,但是通过8666调用时,会报错如下:
"Server failed to execute target method, cause by: NoClassDefFoundError, Could not initialize class com.baidu.cloud.thirdparty.feign.Util"
客户端报错如下: `已经进入了, userId = 1 2023-03-14 18:37:32.452 ERROR 29980 --- [ star-s-biz-2] c.b.c.s.core.rpc.RpcServiceInvoker : Failed to execute method getUser, caused by
java.lang.reflect.InvocationTargetException: null at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na] at com.baidu.cloud.starlight.core.rpc.RpcServiceInvoker.invoke(RpcServiceInvoker.java:85) ~[starlight-all-2022.2.0.jar:na]`
请教该如何处理?
开发者您好, 根据Wiki所示,provider的impl继承的是UserRestService,看代码里是UserService,请问是否是写错了。 另外,看DEMO里UserService类并没有添加@RequestMapping和@GetMapping,这样客户端通过httprest调用服务端是不是无法做到? 我用两个SpringBoot项目,分别作为客户端和服务端,客户端和服务端使用了代码一模一样的UserService和UserServiceImpl。我在UserRestServiceImpl中注释掉了rest调用。通过curl调用客户端的GET方法,返回值报错:
"Server failed to execute target method, cause by: StarlightRpcException, Service {com.example.clientdemo.service.UserService} not found in provider"
而我看客户端报错如下:
`2023-03-14 18:00:48.534 INFO 29835 --- [ star-s-biz-7] c.b.cloud.starlight.api.utils.LogUtils : [REQLOG] reqTime 18:00:48.505, recvTime 18:00:48.529, remoteName null, remoteAddr localhost:8777, protocol brpc, status 1001, cost 31, req UserService:getUser, encReqBody 0, waitForIoExec 3, encReqHead 1, serverExec 24, decRespHead 2, waitForExec 1, decRespBody null, tid null, spid null 2023-03-14 18:00:48.542 ERROR 29835 --- [ star-s-biz-9] c.b.c.s.core.rpc.RpcServiceInvoker : Failed to execute method getUser, caused by
java.lang.reflect.InvocationTargetException: null at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na] at com.baidu.cloud.starlight.core.rpc.RpcServiceInvoker.invoke(RpcServiceInvoker.java:85) ~[starlight-all-2022.2.0.jar:na] at com.baidu.cloud.starlight.core.filter.ServerMonitorFilter.filterRequest(ServerMonitorFilter.java:32) ~[starlight-all-2022.2.0.jar:na] at com.baidu.cloud.starlight.core.filter.FilterChain$2.invoke(FilterChain.java:116) ~[starlight-all-2022.2.0.jar:na] at com.baidu.cloud.starlight.core.filter.GenericFilter.filterRequest(GenericFilter.java:81) ~[starlight-all-2022.2.0.jar:na]`
‘2023-03-14 18:00:48.546 INFO 29835 --- [ star-s-nio-4-5] c.b.cloud.starlight.api.utils.LogUtils : [ACCLOG] recvTime 18:00:48.484, respTime 18:00:48.546, remoteName null, remoteAddr 127.0.0.1:61369, protocol springrest, status 1006, cost 62, req UserRestService:getUser, decReqHead 12, waitForExec 1, decodeReqBody 0, execServFilter 0, execMethod null, encRespBody 2, waitForIoExec 0, encRespHead 1, tid null, spid null 2023-03-14 18:00:48.549 INFO 29835 --- [ star-s-nio-4-5] c.b.c.s.transport.netty.RpcHandler : Server Channel is closing, channelId ’
服务端有控制台输出:
2023-03-14 18:00:48.523 INFO 29832 --- [ star-s-nio-3-1] c.b.cloud.starlight.api.utils.LogUtils : [ACCLOG] recvTime 18:00:48.513, respTime 18:00:48.521, remoteName null, remoteAddr 127.0.0.1:60388, protocol brpc, status 1001, cost 8, req UserService:getUser, decReqHead 6, waitForExec null, decodeReqBody null, execServFilter null, execMethod null, encRespBody 0, waitForIoExec 0, encRespHead 1, tid null, spid null
请教该如何处理?客户端和服务端应当是分开的,很难像您DEMO一样是同一个文件,只能保证文件内容相同。
另外我这里服务启动后一直报错,似乎并不影响使用,也想请教您该如何处理?:
`2023-03-14 18:00:53.101 WARN 29832 --- [ DirectMem--1] c.b.c.s.t.netty.DirectMemoryReporter : Get DIRECT_MEMORY_COUNTER from directMemory failed.
java.lang.NullPointerException: null at com.baidu.cloud.starlight.transport.netty.DirectMemoryReporter.lambda$report$0(DirectMemoryReporter.java:64) ~[starlight-all-2022.2.0.jar:na] at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) ~[na:na] at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305) ~[na:na] at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305) ~[na:na] at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na] at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na] at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]`
盼能得到您的答复,谢谢