This commit is contained in:
Marcin Grzejszczak
2019-03-22 15:08:40 +01:00
parent 036bb73c73
commit a607ccf376
5 changed files with 50 additions and 44 deletions

View File

@@ -18,8 +18,10 @@ package com.example.loan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@SpringBootApplication
@EnableConfigurationProperties(ServiceConfiguration.class)
public class Application {
public static void main(String[] args) {

View File

@@ -32,17 +32,17 @@ import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
@Service
@ConfigurationProperties("service")
public class LoanApplicationService {
private static final String FRAUD_SERVICE_JSON_VERSION_1 = "application/vnd.fraud.v1+json";
private final RestTemplate restTemplate;
private int port = 8080;
private final ServiceConfiguration serviceConfiguration;
public LoanApplicationService() {
public LoanApplicationService(ServiceConfiguration serviceConfiguration) {
this.restTemplate = new RestTemplate();
this.serviceConfiguration = serviceConfiguration;
}
public LoanApplicationResult loanApplication(LoanApplication loanApplication) {
@@ -60,7 +60,7 @@ public class LoanApplicationService {
// tag::client_call_server[]
ResponseEntity<FraudServiceResponse> response = this.restTemplate.exchange(
"http://localhost:" + this.port + "/fraudcheck", HttpMethod.PUT,
"http://localhost:" + getPort() + "/fraudcheck", HttpMethod.PUT,
new HttpEntity<>(request, httpHeaders), FraudServiceResponse.class);
// end::client_call_server[]
@@ -81,8 +81,26 @@ public class LoanApplicationService {
response.getRejectionReason());
}
public int getPort() {
return this.serviceConfiguration.getPort();
}
public void setPort(int port) {
this.port = port;
this.serviceConfiguration.setPort(port);
}
}
@ConfigurationProperties("service")
class ServiceConfiguration {
private int port = 8080;
public int getPort() {
return port;
}
public void setPort(int port) {
this.port = port;
}
}