STEP 12 Set Up new Microservice CurrencyExchange Service with hardcoded Value

 STEP 1 


Pom.xml will have given given below dependencies

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-parent</artifactId>

<version>2.7.15</version>

<relativePath/> <!-- lookup parent from repository -->

</parent>

<groupId>com.khan.microserservices</groupId>

<artifactId>currency-exchange-service</artifactId>

<version>0.0.1-SNAPSHOT</version>

<name>currency-exchange-service</name>

<description>currency-exchange-service demo app</description>

<properties>

<java.version>17</java.version>

<spring-cloud.version>2021.0.8</spring-cloud.version>

</properties>

<dependencies>

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-actuator</artifactId>

</dependency>

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-web</artifactId>

</dependency>

<dependency>

<groupId>org.springframework.cloud</groupId>

<artifactId>spring-cloud-starter-config</artifactId>

</dependency>


<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-devtools</artifactId>

<scope>runtime</scope>

<optional>true</optional>

</dependency>

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-test</artifactId>

<scope>test</scope>

</dependency>

<dependency>

<groupId>org.springframework.cloud</groupId>

<artifactId>spring-cloud-starter-bootstrap</artifactId>

</dependency>

</dependencies>

<dependencyManagement>

<dependencies>

<dependency>

<groupId>org.springframework.cloud</groupId>

<artifactId>spring-cloud-dependencies</artifactId>

<version>${spring-cloud.version}</version>

<type>pom</type>

<scope>import</scope>

</dependency>

</dependencies>

</dependencyManagement>


<build>

<plugins>

<plugin>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-maven-plugin</artifactId>

</plugin>

</plugins>

</build>


</project>


1. CurrencyExchangeServiceApplication will be the main class


@SpringBootApplication

public class CurrencyExchangeServiceApplication {


public static void main(String[] args) {

SpringApplication.run(CurrencyExchangeServiceApplication.class, args);

}


}


2. CurrencyExchangeController will be the Controller Class


@RestController

public class CurrencyExchangeController {


@GetMapping("currency-exchange/from/{from}/to/{to}")

public ExchangeValue retrieveExchangeValue(@PathVariable String from, @PathVariable String to) {

return new ExchangeValue(1L, from, to, BigDecimal.valueOf(81));

}

}


ExchangeValue will be the Response Entity class


public class ExchangeValue {


private Long id;

private String from;

private String to;

private BigDecimal conversionMultiple;

public ExchangeValue() {

}


public ExchangeValue(Long id, String from, String to, BigDecimal conversionMultiple) {

super();

this.id = id;

this.from = from;

this.to = to;

this.conversionMultiple = conversionMultiple;

}


public Long getId() {

return id;

}


public String getFrom() {

return from;

}


public String getTo() {

return to;

}


public BigDecimal getConversionMultiple() {

return conversionMultiple;

}

}


3. application.properties will have given below property to run


spring.application.name=currency-exchange-service

server.port=8000

Comments

Popular posts from this blog

Microservice with Java Spring Cloud

STEP 10 Configure Porfile for Limit service

STEP 9 Connect Limit service to Spring Cloud Config Server