尝试重写NamingProxy内的函数时出现java错误[构造函数的参数0]
我试图自定义NamingProxy中的一些函数,这样就可以排除单独的服务器,这些服务器也需要注册到nacos中
但面临一些问题:
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of constructor in com.gof.springcloud.loadbalancer.CustomNamingProxy required a bean of type 'java.lang.String' that could not be found.
Action:
Consider defining a bean of type 'java.lang.String' in your configuration.
自定义代码如下所示:
自定义代理
public class CustomNamingProxy extends NamingProxy {
public CustomNamingProxy(String namespaceId, String endpoint, String serverList, Properties properties) {
super(namespaceId, endpoint, serverList, properties);
}
@Override
public String reqApi(String api, Map<String, String> params, Map<String, String> body, String method)
throws NacosException {
return reqApi(api, params, body, getMyServerList(), method);
}
private List<String> getMyServerList() {
// TODO
return null;
}
}
SpringBoot应用程序
@SpringBootApplication
@EnableDiscoveryClient
@EnableCaching
@ComponentScan(includeFilters = {
@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = { NamingProxy.class }) })
public class Gateway9111_App {
public static void main(String[] args) {
SpringApplication.run(Gateway9111_App.class, args);
}
}
# 1 楼答案
您的代码没有返回任何服务列表。首先,填写
// TODO
行