Write Simple Spring Boot App for get currency rate

Yegor Voronyansky
3 min readDec 8, 2020

Within the framework of this article, we will develop an application for receiving exchange rates from the central bank of Russia. The main technologies we will be using will be Java, Spring Boot, Docker, Vue

1. Let’s start by choosing the required method in the API of the central bank, which is allowed to get the current rates
2. Next, let’s add WSDL processing to the application so that we don’t have to do it by hand
3. We use Spring WebServices so that our application can skillfully request data from the API
4. Add Swagger to the application
5. Add some Vue frontend
6. Connect Docker
The first thing we need is, of course, to create an application — this can be done using the Spring Initializr or through IntelliJ IDEA.

Creation of the project

The API method we’ll be using from the central bank is called GetCursOnDateXML. Below you can see its description.

Description of this method

In order not to describe the structure of requests and responses from the API ourselves, we will use plugins that will help turn WSDL into POJO. Listing pom.xml

Let’s check that the plugin really works and the classes we need are created — screen.

Generate POJO from WSDL

Now let’s add a web service that will be responsible for executing the request and response. Listing of creating a web service.

Great, the MVP of the application is almost complete. Now let’s add REST controllers so that we can send the received data from the third-party API outside. We will have one controller and two entry points — receiving all currencies, and receiving a specific currency at the moment.

Entrypoints of application

Let’s add Swagger to our application so that all consumers of our API know the contracts for interacting with the system.In order to add Swagger, you need to add one dependency and write the configuration code. Let’s check that Swagger actually works. However, we need a complete UI. To do this, let’s add another dependency and make sure that everything worked correctly.

Add Swagger and Swagger UI

We have an API, but at the moment we can display currencies only in JSON form. Let’s add a little frontend in Vue.

Front end part

Now, we should add service instance for interact with our backend.

We’ll also add Docker for our convenience. Our Dockerfile will look like this

Simple Dockerfile

Let’s run our application

Our app is working!

And last, but not least let’s write unit test — for check that our app works correctly

First test
Second test

That’s all for me, I hope you liked the article Write comments and subscribe

--

--

Yegor Voronyansky

I am a Software Engineer, JVM enthusiast, cat - lover, part-time surfer.