错误如下所示:
第一, 检查maven下的pom文件是否正确导入所有的包
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.5.RELEASE</version> <relativePath></relativePath> </parent>
<dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Brixton.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
<dependencies> <!-- 导入ribbon依赖 --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-ribbon</artifactId> </dependency> <!-- 导入eureka依赖, 进行服务注册 --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> </dependency> <!-- 导入spring-boot依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies>
|
第二, 检查是否有BeanFactory中是否存在RestTemplate, 并有无加载注解@LoadBalanced
1 2 3 4 5
| @Bean @LoadBalanced public RestTemplate restTemplate() { return new RestTemplate(); }
|
第三, 检查是否填写错误路由
1 2 3 4 5
| @RequestMapping(value="/add", method=RequestMethod.GET) public String addService() { // 正确代码: "http://COMPUTE-SERVICE/add?a=10&b=30" return restTemplate.getForEntity("COMPUTE-SERVICE/add?a=10&b=30", String.class).getBody(); }
|