Skip to content

Commit 2943a74

Browse files
committed
Move local profile base URL to config
1 parent 5fcce13 commit 2943a74

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/main/java/org/squidmin/java/spring/reactive/service/RecommendationServiceImpl.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.squidmin.java.spring.reactive.service;
22

3+
import org.springframework.beans.factory.annotation.Value;
34
import org.springframework.core.ParameterizedTypeReference;
45
import org.springframework.stereotype.Service;
56
import org.springframework.web.reactive.function.client.WebClient;
@@ -12,24 +13,26 @@
1213
@Service
1314
public class RecommendationServiceImpl implements RecommendationService {
1415

16+
private final String baseUrl;
1517
private final WebClient webClient;
1618

17-
public RecommendationServiceImpl(WebClient webClient) {
19+
public RecommendationServiceImpl(@Value("${product-recommendations.base-url}") String baseUrl, WebClient webClient) {
20+
this.baseUrl = baseUrl;
1821
this.webClient = webClient;
1922
}
2023

2124
@Override
2225
public Flux<Product> getRecommendations(Long productId) {
2326
Mono<List<Product>> purchaseHistoryRecommendation = webClient
2427
.get()
25-
.uri("http://localhost:8000/products/{id}/purchaseHistory", productId)
28+
.uri("http://" + baseUrl + "/products/{id}/purchaseHistory", productId)
2629
.retrieve()
2730
.bodyToMono(new ParameterizedTypeReference<List<Product>>() {
2831
});
2932

3033
Mono<List<Product>> coOccurrenceRecommendation = webClient
3134
.get()
32-
.uri("http://localhost:8000/products/{id}/coOccurrence", productId)
35+
.uri("http://" + baseUrl + "/products/{id}/coOccurrence", productId)
3336
.retrieve()
3437
.bodyToMono(new ParameterizedTypeReference<List<Product>>() {
3538
});

src/main/resources/application.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
spring:
22
application:
3-
name: java-spring-reactive-web-reference
3+
name: java-spring-reactive-web-reference
4+
5+
product-recommendations:
6+
base-url: localhost:8000

0 commit comments

Comments
 (0)