@RequestMapping(value = "/get", method = GET)
@ResponseBody
public String get(@RequestParam String serviceName) throws NacosException {
List<Instance> ret= namingService.getAllInstances(serviceName);
Instance nacosServer=(Instance) ret.get(0);
ISysClient sysClient= (ISysClient) nacosServer; //这里报错误了
R<String> retData=sysClient.getDeptIds(11L,"dd");
System.out.printf("ret="+retData);
return "";
}
报错:
java.lang.ClassCastException: com.alibaba.nacos.api.naming.pojo.Instance cannot be cast to com.alibaba.nacos.example.spring.controller.ISysClient
at com.alibaba.nacos.example.spring.controller.DiscoveryController.get(DiscoveryController.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:743)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:672)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:82)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:933)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:867)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:951)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:842)
拿到了Instance成功了,怎么用, 不然拿到了也没用