Working Eureka

eureka
atancito 2022-10-02 16:38:27 +02:00
parent c2530c3782
commit 5c8623a937
5 changed files with 8 additions and 7 deletions

View File

@ -15,7 +15,6 @@
<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>

View File

@ -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();
}

View File

@ -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);

View File

@ -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);

View File

@ -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) {