Home

Building a RESTful API with Spring Boot

Introduction
This article describe beginner level implementation of REST Service using Spring Boot. The sample presented is simple REST controller which returns a response to the user. Spring Boot complements Spring REST support by providing default dependencies/converters out of the box. Writing RESTful service in Spring Boot is no-different than Spring MVC. If you are a REST Client [Rest Consumer], Spring Boot provides RestTemplateBuilder that can be used to customize the RestTemplate before calling the REST endpoints. To summarize, Spring Boot based REST service is exactly same as Spring based REST service, only differing in the way with we bootstrap the underlying application.
Overview
In Rest based design, resources are being manipulated using a common set of verbs.
Ø  To Create a resource : HTTP POST should be used
Ø  To Retrieve a resource : HTTP GET should be used
Ø  To Update a resource : HTTP PUT should be used
Ø  To Delete a resource : HTTP DELETE should be used
Prerequirests:
Ø  Exclips
Ø  JDK 1.8 or later
Ø  Maven 3.0+
Ø  Spring Boot
Implementation
Step1: Create a Maven project:
File à New à Maven Project and click on next. Uncheck Archetype selection and  click on next.
Enter Group id as ‘com.eai.integration’ and Artifact Id as ‘Integration-API-Customer’ than click on finish.
Step 2: Add the Dependencies to pom.xml. Add the following code to pom.xml
These dependencies are for Spring boot, Spring data and embaded H2 data base.

 4.0.0
 com.eai.integration
 Integration-API-Customer
 0.0.1-SNAPSHOT
 Integration-API-Customer
 Integration-API-Customer

 
  org.springframework.boot
  spring-boot-starter-parent
  1.5.7.RELEASE
 

 
  
   org.springframework.boot
   spring-boot-starter-web
  
  
   org.springframework.boot
   spring-boot-starter-data-jpa
  
  
   org.springframework.boot
   spring-boot-starter-actuator
  
  
   org.springframework.boot
   spring-boot-starter-test
   test
  
  
  
   com.h2database
   h2
  
  
   org.springframework.data
   spring-data-rest-core
  
 

 
  1.8
 

 
  
   
    org.springframework.boot
    spring-boot-maven-plugin
   
  
 

Step 3: Create an executable main class
Create a simple Java class to run the Spring Boot application and add the below code.
/**
 * 
 */
package com.eai.integration;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * @author Ameer
 *
 */
@SpringBootApplication
public class CustomerApplication {

 public static void main(String[] args) {
  SpringApplication.run(CustomerApplication.class, args);
 }
}

The @SpringBootApplication annotation provides a load of defaults (like the embedded servlet container) depending on the contents of your classpath, and other things. It also turns on Spring MVC’s @EnableWebMvc annotation that activates web endpoints.
Step 4: Create a Pojo calss called as ‘Customer’ and add below code.
/**
 * 
 */
package com.eai.integration.bo;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

/**
 * @author Ameer
 *
 */
@Entity
public class Customer {
 @Id
 @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;
 private Integer customerID;
 private String name;
 private String customerType;
 private String address;
 
 public Integer getId() {
  return id;
 }
 public void setId(Integer id) {
  this.id = id;
 }
 public Integer getCustomerID() {
  return customerID;
 }
 public void setCustomerID(Integer customerID) {
  this.customerID = customerID;
 }
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 public String getCustomerType() {
  return customerType;
 }
 public void setCustomerType(String customerType) {
  this.customerType = customerType;
 }
 public String getAddress() {
  return address;
 }
 public void setAddress(String address) {
  this.address = address;
 }
}
Create a repository interface called as ‘CustomerRepository’ to store/retrieve from H2 data base and add following code.
package com.eai.integration.repository;

import org.springframework.data.repository.CrudRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

import com.eai.integration.bo.Customer;

@RepositoryRestResource
public interface CustomerRepository extends CrudRepository{
 Customer findByCustomerID(Integer customerID);
}
Create a H2 data base configuration class called as ‘H2DatabaseConfig’ and add follwing code.
package com.eai.integration.config;

import org.h2.server.web.WebServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class H2DatabaseConfig {
 @Bean
    ServletRegistrationBean h2servletRegistration(){
        ServletRegistrationBean registrationBean = new ServletRegistrationBean( new WebServlet());
        registrationBean.addUrlMappings("/h2/*");
        return registrationBean;
    }
}
Create a Controller calss called as ‘CustomerController and add following code.
package com.eai.integration.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.eai.integration.bo.Customer;
import com.eai.integration.repository.CustomerRepository;

/**
 * @author Ameer
 *
 */
@RestController
@RequestMapping("/api")
public class CustomerController {
 @Autowired
 private CustomerRepository customerRepository;
 
 @RequestMapping(value = "/customer/{customerID}", method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_VALUE})
    public @ResponseBody Customer getCustomer(@PathVariable Integer customerID) {
  Customer customer = customerRepository.findByCustomerID(customerID);
        return customer;
    }
 
 @RequestMapping(value = "/customer", method = RequestMethod.POST, produces = {MediaType.APPLICATION_JSON_VALUE})
    public @ResponseBody String createCustomer(@RequestBody Customer customer) {
  customerRepository.save(customer);
  String message = "Customer Created successfully";
        return message;
    }
}
The class is flagged as a @RestController, meaning it’s ready for use by Spring MVC to handle web requests. @RequestMapping maps / to the index() method. When invoked from a browser or using curl on the command line, the method returns pure text. That’s because @RestController combines @Controller and @ResponseBody, two annotations that results in web requests returning data rather than a view.
Test the Application
Now start the application by running main() method in SpringBootDemoApplication. It will start the embedded tomcat server on port 8080.
Right click on project select Run As à Spring Boot App.
Now we can see our application is started and able to listen at 8080 port.
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.5.7.RELEASE)

2017-09-26 15:58:28.545  INFO 1148 --- [           main] com.eai.integration.CustomerApplication  : Starting CustomerApplication on DESKTOP-A5OPFCC with PID 1148 (C:\Users\AmeerGodugu\git\SpringBoot\Integration-API-Customer\target\classes started by AmeerGodugu in C:\Users\AmeerGodugu\git\SpringBoot\Integration-API-Customer)
2017-09-26 15:58:28.545  INFO 1148 --- [           main] com.eai.integration.CustomerApplication  : No active profile set, falling back to default profiles: default
2017-09-26 15:58:28.576  INFO 1148 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@4206a205: startup date [Tue Sep 26 15:58:28 IST 2017]; root of context hierarchy
2017-09-26 15:58:29.264  INFO 1148 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'managementServletContext' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.actuate.autoconfigure.EndpointWebMvcHypermediaManagementContextConfiguration; factoryMethodName=managementServletContext; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/actuate/autoconfigure/EndpointWebMvcHypermediaManagementContextConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration; factoryMethodName=managementServletContext; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.class]]
2017-09-26 15:58:29.693  INFO 1148 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$e7a3d0e6] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-09-26 15:58:30.068  INFO 1148 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2017-09-26 15:58:30.068  INFO 1148 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2017-09-26 15:58:30.068  INFO 1148 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.20
2017-09-26 15:58:30.568  INFO 1148 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2017-09-26 15:58:30.568  INFO 1148 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1992 ms
2017-09-26 15:58:30.762  INFO 1148 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'webServlet' to [/h2/*]
2017-09-26 15:58:30.762  INFO 1148 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
2017-09-26 15:58:30.762  INFO 1148 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'metricsFilter' to: [/*]
2017-09-26 15:58:30.762  INFO 1148 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-09-26 15:58:30.762  INFO 1148 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-09-26 15:58:30.762  INFO 1148 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-09-26 15:58:30.762  INFO 1148 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2017-09-26 15:58:30.762  INFO 1148 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'webRequestLoggingFilter' to: [/*]
2017-09-26 15:58:30.762  INFO 1148 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'applicationContextIdFilter' to: [/*]
2017-09-26 15:58:31.090  INFO 1148 --- [           main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2017-09-26 15:58:31.106  INFO 1148 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
 name: default
 ...]
2017-09-26 15:58:31.153  INFO 1148 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.0.12.Final}
2017-09-26 15:58:31.153  INFO 1148 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2017-09-26 15:58:31.153  INFO 1148 --- [           main] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
2017-09-26 15:58:31.184  INFO 1148 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2017-09-26 15:58:31.262  INFO 1148 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2017-09-26 15:58:31.637  INFO 1148 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000227: Running hbm2ddl schema export
2017-09-26 15:58:31.651  INFO 1148 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000230: Schema export complete
2017-09-26 15:58:31.666  INFO 1148 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2017-09-26 15:58:32.142  INFO 1148 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@4206a205: startup date [Tue Sep 26 15:58:28 IST 2017]; root of context hierarchy
2017-09-26 15:58:32.142  INFO 1148 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Detected ResponseBodyAdvice bean in org.springframework.boot.actuate.autoconfigure.EndpointWebMvcHypermediaManagementContextConfiguration$ActuatorEndpointLinksAdvice
2017-09-26 15:58:32.189  INFO 1148 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/api/customer],methods=[POST],produces=[application/json]}" onto public java.lang.String com.eai.integration.controller.CustomerController.createCustomer(com.eai.integration.bo.Customer)
2017-09-26 15:58:32.189  INFO 1148 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/api/customer/{customerID}],methods=[GET],produces=[application/json]}" onto public com.eai.integration.bo.Customer com.eai.integration.controller.CustomerController.getCustomer(java.lang.Integer)
2017-09-26 15:58:32.189  INFO 1148 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2017-09-26 15:58:32.189  INFO 1148 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2017-09-26 15:58:32.220  INFO 1148 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-09-26 15:58:32.220  INFO 1148 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-09-26 15:58:32.235  INFO 1148 --- [           main] .m.m.a.ExceptionHandlerExceptionResolver : Detected ResponseBodyAdvice implementation in org.springframework.boot.actuate.autoconfigure.EndpointWebMvcHypermediaManagementContextConfiguration$ActuatorEndpointLinksAdvice
2017-09-26 15:58:32.251  INFO 1148 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-09-26 15:58:32.626  INFO 1148 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/mappings || /mappings.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-09-26 15:58:32.626  INFO 1148 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/loggers/{name:.*}],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.LoggersMvcEndpoint.get(java.lang.String)
2017-09-26 15:58:32.626  INFO 1148 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/loggers/{name:.*}],methods=[POST],consumes=[application/vnd.spring-boot.actuator.v1+json || application/json],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.LoggersMvcEndpoint.set(java.lang.String,java.util.Map)
2017-09-26 15:58:32.626  INFO 1148 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/loggers || /loggers.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-09-26 15:58:32.626  INFO 1148 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/trace || /trace.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-09-26 15:58:32.626  INFO 1148 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/autoconfig || /autoconfig.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-09-26 15:58:32.626  INFO 1148 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/metrics/{name:.*}],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.MetricsMvcEndpoint.value(java.lang.String)
2017-09-26 15:58:32.626  INFO 1148 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/metrics || /metrics.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-09-26 15:58:32.626  INFO 1148 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/configprops || /configprops.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-09-26 15:58:32.626  INFO 1148 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/auditevents || /auditevents.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public org.springframework.http.ResponseEntity org.springframework.boot.actuate.endpoint.mvc.AuditEventsMvcEndpoint.findByPrincipalAndAfterAndType(java.lang.String,java.util.Date,java.lang.String)
2017-09-26 15:58:32.626  INFO 1148 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/health || /health.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint.invoke(javax.servlet.http.HttpServletRequest,java.security.Principal)
2017-09-26 15:58:32.626  INFO 1148 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/info || /info.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-09-26 15:58:32.626  INFO 1148 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/heapdump || /heapdump.json],methods=[GET],produces=[application/octet-stream]}" onto public void org.springframework.boot.actuate.endpoint.mvc.HeapdumpMvcEndpoint.invoke(boolean,javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws java.io.IOException,javax.servlet.ServletException
2017-09-26 15:58:32.626  INFO 1148 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/env/{name:.*}],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EnvironmentMvcEndpoint.value(java.lang.String)
2017-09-26 15:58:32.626  INFO 1148 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/env || /env.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-09-26 15:58:32.626  INFO 1148 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/dump || /dump.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-09-26 15:58:32.626  INFO 1148 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/actuator || /actuator.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public org.springframework.hateoas.ResourceSupport org.springframework.boot.actuate.endpoint.mvc.HalJsonMvcEndpoint.links()
2017-09-26 15:58:32.626  INFO 1148 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/beans || /beans.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-09-26 15:58:32.814  INFO 1148 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2017-09-26 15:58:32.823  INFO 1148 --- [           main] o.s.c.support.DefaultLifecycleProcessor  : Starting beans in phase 0
2017-09-26 15:58:32.916  INFO 1148 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2017-09-26 15:58:32.916  INFO 1148 --- [           main] com.eai.integration.CustomerApplication  : Started CustomerApplication in 4.559 seconds (JVM running for 5.09)
Now our application is started and ready for testing. We can use Soap UI/Postman or any rest API test tools. I am using one of the Rest API tool which is provided by google chrome plug-in. I have opened the tool and entered below details.
Click on Send, we will see success response in Response tab as shown below.
Here we have tested POST method to create an account. This data is stored into H2 database. We can open the H2 database console and see the results. 
Now we can test GET method to fetch the results from H2 database. I have entered rest uri for GET as shown below and click on Send. We will see results as shown below.
Conclusion
This article presented a basic Spring Boot restful API tutorial. We added a simple web controller as well as a main program which invokes the Spring Framework. In further articles, we will explore other aspects of the Spring Boot Framework.
Download
S. No
File Name
Size
Download
1
Building a RESTful API with Spring Boot.pdf
1.6 MB

Comments