Now is the time to pick the IDE. Though there are many IDEs used for Spring Boot projects, I would recommend using Spring Tool Suite (STS), as it is open source and easy to manage projects with. In my case, I use sts-3.8.2.RELEASE. You can download the latest STS from this link: https://spring.io/tools/sts/all. In most cases, you may not need to install; just unzip the file and start using it:
After extracting the STS, you can start using the tool by running STS.exe (shown in the preceding screenshot).
In STS, you can import the project by selecting Existing Maven Projects, shown as follows:
After importing the project, you can see the project in Package Explorer, as shown in the following screenshot:
You can see the main Java file (TicketManagementApplication) by default:
To simplify the project, we will clean up the existing POM file and update the required dependencies. Add this file configuration to pom.xml:
In the preceding configuration, you can check that we have used the following libraries:
spring-web
spring-boot-starter
spring-boot-starter-tomcat
spring-bind
jackson-databind
As the preceding dependencies are needed for the project to run, we have added them to our pom.xml file.
So far we have got the base project ready for Spring Web Service. Let's add a basic REST code to the application. First, remove the @SpringBootApplication annotation from the TicketManagementApplication class and add the following annotations:
These annotations will help the class to act as a web service class. I am not going to talk much about what these configurations will do in this chapter. After adding the annotations, please add a simple method to return a string as our basic web service method:
@ResponseBody @RequestMapping("/") public String sayAloha(){ return "Aloha"; }
Once all the coding changes are done, just run the project on Spring Boot App (Run As | Spring Boot App). You can verify the application has loaded by checking this message in the console:
Tomcat started on port(s): 8080 (http)
Once verified, you can check the API on the browser by simply typing localhost:8080. Check out the following screenshot:
If you want to change the port number, you can configure a different port number in application.properties, which is in src/main/resources/application.properties. Check out the following screenshot: