Fixed
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -33,20 +33,20 @@ 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();
|
||||
// tag::custom_request_factory[]
|
||||
this.restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory());
|
||||
// end::custom_request_factory[]
|
||||
this.serviceConfiguration = serviceConfiguration;
|
||||
}
|
||||
|
||||
public LoanApplicationResult loanApplication(LoanApplication loanApplication) {
|
||||
@@ -64,7 +64,7 @@ public class LoanApplicationService {
|
||||
|
||||
// tag::client_call_server[]
|
||||
ResponseEntity<FraudServiceResponse> response = restTemplate.exchange(
|
||||
"http://localhost:" + port + "/fraudcheck", HttpMethod.PUT,
|
||||
"http://localhost:" + getPort() + "/fraudcheck", HttpMethod.PUT,
|
||||
new HttpEntity<>(request, httpHeaders), FraudServiceResponse.class);
|
||||
// end::client_call_server[]
|
||||
|
||||
@@ -85,8 +85,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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example.loan;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
@ConfigurationProperties("service")
|
||||
public class ServiceProperties {
|
||||
|
||||
private int port = 8080;
|
||||
|
||||
public int getPort() {
|
||||
return this.port;
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user