Preparing the working environment
Finally, it's time to prepare our working environment. We will prepare all the software needed to develop and run our application. For this process, we will need the following:
For a proper development machine, you can use any computer having, for example, an i5 processor (or more powerful) with at least 8 GB of RAM. These are the main characteristics. You can do your development on Microsoft Windows, Linux, or macOS. All the development mentioned in this book was done on macOS Sierra (version 10.12.6).
We will use Git as our version control system. To install it, follow the procedure for your OS. We will provide guidance for the following:
- Microsoft Windows
- Linux (Debian, Ubuntu, Fedora, and raw source code)
- macOS
Here are the steps for installing Git on Microsoft Windows:
- Download Git for Microsoft Windows from the following location: https://git-for-windows.github.io/.
- Start the installer and follow the instructions.
- Open the Command Prompt.
- Configure Git with the following commands:
$ git config --global user.name "Your Name"
$ git config --global user.email "[email protected]"
To install Git on macOS, we recommend that you install Xcode with command-line tools from the App Store. Then, open Terminal and verify the Git version:
$ git -version
git version 2.7.0 (Apple Git-66)
Follow the installation steps for your distribution.
The following are the steps to install Git on Debian and Ubuntu:
- Open Terminal.
- Use the following commands to start the installation:
$ sudo apt-get update
$ sudo apt-get install git
$ git -version
- The output should be something like the following:
git version 2.9.2
- Configure Git with the following commands:
$ git config --global user.name "Your Name"
$ git config --global user.email "[email protected]"
The following are the steps to install Git on Fedora:
- Open Terminal.
- Depending on your Fedora version, use YUM or DNF to install Git as follows:
$ sudo dnf install git
//or
$ sudo yum install git
$ git -version
- The output should be something like the following:
git version 2.9.2
- Configure Git with the following commands:
$ git config --global user.name "Your Name"
$ git config --global user.email "[email protected]"
Building Git from the source code
If you prefer to build your stuff from source code, you can do the same with Git.
To build from source, you need some dependencies installed:
- Open Terminal and install the following dependencies:
$ sudo apt-get update
$ sudo apt-get install libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev asciidoc xmlto docbook2x
- Navigate to your preferred directory.
- Clone the Git source code as follows:
$ git clone https://git.kernel.org/pub/scm/git/git.git
$ make all doc info prefix=/usr
$ sudo make install install-doc install-html install-info install-man prefix=/usr
Note
We installed Git in the /usr
directory. Use a different filesystem location if you prefer.
The following are the steps to build from the source code:
- As was the case with Debian and Ubuntu, install the dependencies needed to build Git as follows:
$ sudo dnf install curl-devel expat-devel gettext-devel openssl-devel perl-devel zlib-devel asciidoc xmlto docbook2X
- If you have an older version of Fedora, run the following commands:
$ sudo yum install epel-release
$ sudo yum install curl-devel expat-devel gettext-devel openssl-devel perl-devel zlib-devel asciidoc xmlto docbook2X
- Symlink
docbook2X
to the filename that the Git build expects:
$ sudo ln -s /usr/bin/db2x_docbook2texi /usr/bin/docbook2x-texi
- Navigate to your preferred directory.
- Clone the Git source code as follows:
$git clone https://git.kernel.org/pub/scm/git/git.git
$ make all doc prefix=/usr
$ sudo make install install-doc install-html install-man prefix=/usr
Note
We installed Git in the /usr
directory. Use a different filesystem location if you prefer.
Congratulations! You have installed the Git version control system on your machine! You are ready to create repositories that will keep your code. We will do this in Setting up a Git repository section.
As you already know, we will use Kotlin as our primary development language. However, we need Java installed on our system since Kotlin is executed on JVM. Open the Java JDK home page and chose the proper installation depending on the version of your OS: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html.
The following platforms are supported:
- Linux ARM 32 Hard Float ABI
- Linux ARM 64 Hard Float ABI
- Linux x86
- Linux x86
- Linux x64
- Linux x64
- macOS X
- Solaris SPARC 64-bit
- Solaris SPARC 64-bit
- Solaris x64
- Solaris x64
- Windows x86
- Windows x64
Follow the instructions depending on your OS version.
The following are the steps to install JDK in Microsoft Windows:
- Download the proper executable for your version of Microsoft Windows
- Execute the downloaded file
- Follow the instructions
Here are the steps to install JDK in Linux:
- Download the proper RPM Package Manager (RPM) installation package for your platform.
- Open Terminal and install the package:
$ rpm -ihv package_you_downloaded.rpm
- Verify you have installed the Java version:
$ java -version
The following are the steps to install JDK in macOS:
- Download the
dmg
file for your macOS. - Double-click on the
dmg
file to run it. - Double-click on the PKG icon to launch the installation.
- Follow the installation instructions. Enter your system credentials if asked.
- Verify that the Java version from Terminal:
$ java -version
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)
Congratulations! Java is up and running! The next thing we are going to do is set up our IDE.
We chose IntelliJ IDEA as our IDE. Unfortunately, IDEA is not free. It is commercial software. You can buy a license or use IntelliJ IDEA Community Edition, Eclipse, or NetBeans to get it running. Follow the installation instructions for your specific OS.
The following are the steps to install IDEA in Microsoft Windows:
The following are the steps to install IDEA in Linux:
The following are the steps to install IDEA in macOS:
Starting IntelliJ for the first time
You have installed IntelliJ; now it is time for the first run. You will be asked to do some configuring. Don't worry, everything is simple and easy. Just follow the instructions:
- Launch IntelliJ and wait until the
Complete Installation
dialog appears. Choose Don't import settings
and continue by clicking on OK
.
- Next, you will be prompted to select the UI theme. You can choose between the default theme and the
Darcula
theme. We recommend that you use the Darcula
theme:
- In the next section, disable any plugins that are not required:
- In the next step, you are prompted to download additional plugins:
- Finally, you can start the project! The setup is complete, as shown in the following screenshot:
Before installing or running Spring 5, we need to install Kotlin, since this is our primary programming language for the project:
- Open IntelliJ IDEA and choose
Configure
| Plugins
, as shown in the following screenshot:
- In the search field, type
Kotlin
:
- Click on the
Install JetBrains plugin...
button.
- From the list that appears, choose
Kotlin
. - If you do not already have Kotlin installed, you will see a green
Install
button. Click on it, otherwise click on the Update
button, as shown in the following screenshot:
- Wait until the installation or update process completes:
- When the installation is finished, click on the
Restart IntelliJ IDEA
button:
If the Restart IntelliJ IDEA
button does not restart your IDE, do it yourself manually.
Your IDE is ready for development. It is time to finally set up Spring 5! You can use Spring in the same way as any standard Java library. Simply include the appropriate Spring library files in your classpath. Spring does not require any special tool integration, so you can use any IDE or text editor! As you already know, we will stick to IntelliJ IDEA. You can run and debug Spring applications as you would any other Java application.
Spring can be used through Maven or Gradle. It is up to you to choose which suits you better. We will use Gradle in our development but we will give examples of Maven too.
The recommended way to get started using Spring Framework in your project is with a dependency management system. Take a look at the following Maven example:
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.0.0.RC4</version>
</dependency>
</dependencies><repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/libs-milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
Gradle installation requires less code, as the following snippet shows:
repositories {
maven {
url 'https://repo.spring.io/libs-milestone'
}
}
dependencies {
compile 'org.springframework:spring-context:5.0.0.RC4'
}
To try out our API calls, we will need Postman. Postman is a complete toolchain for API development. Postman is designed from the ground up to support the API developer. It offers us an intuitive user interface to send requests, save responses, add tests, and create workflows.
To get Postman, open https://www.getpostman.com/postman and choose your OS.
Microsoft Windows installation
The following are the steps to install Postman in Microsoft Windows:
- Download the setup file
- Run the installer
- Follow the setup instructions
To simplify the installation process, we recommend that you install it through the Google Chrome store. Search for Postman and install it:
Once you have downloaded the Postman-archived application, extract it, then drag the file to the Applications
folder. Double-click on Postman
to open the application.
Postman is installed. Run it and take a look at its UI. We will not go into details on how to use it. It is enough to play a bit. Most of the options are self-explanatory. Enjoy!
The following screenshot shows the Postman application running on macOS: