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