Working Eureka
parent
c2530c3782
commit
5c8623a937
|
@ -15,17 +15,16 @@
|
|||
<description>Demo project for Spring Boot</description>
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<spring-cloud.version>2021.0.4</spring-cloud.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.example.userservice.config;
|
||||
|
||||
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
@ -7,6 +8,7 @@ import org.springframework.web.client.RestTemplate;
|
|||
@Configuration
|
||||
public class RestTemplateConfig {
|
||||
@Bean
|
||||
@LoadBalanced
|
||||
public RestTemplate restTemplate() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||
|
||||
import com.example.userservice.model.Bike;
|
||||
|
||||
@FeignClient(name = "bike-service", url = "http://localhost:8003/bikes")
|
||||
@FeignClient(name = "bike-service", path = "bikes")
|
||||
public interface BikeFeignClient {
|
||||
@PostMapping
|
||||
Bike save(@RequestBody Bike bike);
|
||||
|
|
|
@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||
|
||||
import com.example.userservice.model.Car;
|
||||
|
||||
@FeignClient(name = "car-service", url = "http://localhost:8002/cars")
|
||||
@FeignClient(name = "car-service", path = "cars")
|
||||
public interface CarFeignClient {
|
||||
@PostMapping
|
||||
Car save(@RequestBody Car car);
|
||||
|
|
|
@ -39,11 +39,11 @@ public class UserService {
|
|||
}
|
||||
|
||||
public List<Car> getCars(int userId) {
|
||||
return restTemplate.getForObject("http://localhost:8002/cars/byuser/" + userId, List.class);
|
||||
return restTemplate.getForObject("http://car-service/cars/byuser/" + userId, List.class);
|
||||
}
|
||||
|
||||
public List<Bike> getBikes(int userId) {
|
||||
return restTemplate.getForObject("http://localhost:8003/bikes/byuser/" + userId, List.class);
|
||||
return restTemplate.getForObject("http://bike-service/bikes/byuser/" + userId, List.class);
|
||||
}
|
||||
|
||||
public Car saveCar(Car car, int userId) {
|
||||
|
|
Loading…
Reference in New Issue