Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring引导云:没有api.github.com可用的实例_Java_Spring Cloud_Github Api_Resttemplate - Fatal编程技术网

Java Spring引导云:没有api.github.com可用的实例

Java Spring引导云:没有api.github.com可用的实例,java,spring-cloud,github-api,resttemplate,Java,Spring Cloud,Github Api,Resttemplate,我目前在微服务公司工作 尝试调用github API时出现以下错误: java.lang.IllegalStateException:没有api.github.com可用的实例 在org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.execute(RibbonLoadBalancerClient.java:119)~[spring-cloud-netflix-ribbon-2.2.1.RELEASE.jar:2.2.

我目前在微服务公司工作

尝试调用github API时出现以下错误:

java.lang.IllegalStateException:没有api.github.com可用的实例
在org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.execute(RibbonLoadBalancerClient.java:119)~[spring-cloud-netflix-ribbon-2.2.1.RELEASE.jar:2.2.1.RELEASE]
在org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.execute(RibbonLoadBalancerClient.java:99)~[spring-cloud-netflix-ribbon-2.2.1.RELEASE.jar:2.2.1.RELEASE]
在org.springframework.cloud.client.loadbalancer.LoadBalancerInterceptor.intercept(LoadBalancerInterceptor.java:58)~[spring-cloud-commons-2.2.1.RELEASE.jar:2.2.1.RELEASE]
我正在使用Discovery Server,这是调用外部API的代码

package com.github.ProjectAPI.resources;
导入com.github.ProjectAPI.models.GithubProject;
导入org.springframework.beans.factory.annotation.Autowired;
导入org.springframework.web.bind.annotation.PathVariable;
导入org.springframework.web.bind.annotation.RequestMapping;
导入org.springframework.web.bind.annotation.RestController;
导入org.springframework.web.client.rest模板;
导入java.util.array;
@RestController
@请求映射(“/project”)
公共类GitubSingleProjectResource{
@自动连线
私有RestTemplate RestTemplate;
@请求映射(“/{projectId}”)
公共列表getMovieInfo(@PathVariable(“projectId”)字符串projectId)
{
GithubProject[]githubProjects=restTemplate.getForObject(“https://api.github.com/users/XXXX/repos“,GithubProject[]类);
List projectsList=Arrays.asList(githubProjects);
返回项目列表;
}
}
有什么建议吗? 当我调用像localhost这样的URL时,一切正常

我是如何做豆子的:

@springboot应用程序
@启用EUREKACLIENT
公共类项目应用程序{
@豆子
@负载平衡
公共RestTemplate getRestTemplate(){
返回新的RestTemplate();
}
公共静态void main(字符串[]args){
run(ProjectApiApplication.class,args);
}
解决方案:

我将java依赖性从11改为8,它可以正常工作


4.0.0
org.springframework.boot
spring启动程序父级
2.2.4.1发布
com.github
ProjectAPI
0.0.1-快照
ProjectAPI
SpringBoot的演示项目
1.8
格林威治释放
org.springframework.boot
SpringBootStarterWeb
org.springframework.cloud
spring cloud starter netflix eureka客户端
org.springframework.boot
弹簧起动试验
测试
org.springframework.cloud
spring云依赖关系
${spring cloud.version}
聚甲醛
进口
org.springframework.boot
springbootmaven插件
春季里程碑
春季里程碑
https://repo.spring.io/milestone

您是如何在另一个类中创建
RestTemplate
?这是bean。请展示上面创建的bean。我编辑了这篇文章。您不能将普通url与负载平衡的rest模板一起使用。请参阅有关提供2个rest模板来使用的文档降级JDK看起来并不是解决问题的真正方法。