Objective

This is the first step towards building our first microservice – the catalog-service. In this step we will create a web application using spring-boot framework and run it.

Technologies used

  1. Java
  2. Spring boot
  3. gradle

Create the web application

  • Create a web application using gradle. Add a build.gradle file with the required dependencies:
compile("org.springframework.boot:spring-boot-starter-web")

The “spring-boot-starter-web” dependency does all the auto-configuration for a web application. It includes a tomcat container.

  • The buildscript also depends on the plugin: –
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.1.RELEASE")

This plugin gives the ability to launch bootRun from gradle (to run a spring boot application)

  • Create a Main class – CatalogServer annotated to identify it as a Spring Boot app.
@SpringBootApplication

The main method will start the Spring Boot application.

SpringApplication.run(CatalogServer.class, args);

Build the web application

gradle build

Run the spring boot application

gradle bootRun

Source Code

Tag: – “step1” in repository: – “catalog-service

git clone https://github.com/microxs-demo/catalog-service
cd catalog-service
git checkout tags/step1

Video

Step 1 video

Advertisements