{"id":74701,"date":"2018-03-13T07:00:39","date_gmt":"2018-03-13T05:00:39","guid":{"rendered":"https:\/\/www.javacodegeeks.com\/?p=74701"},"modified":"2018-03-12T11:11:21","modified_gmt":"2018-03-12T09:11:21","slug":"build-rest-web-service-using-spring-boot","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2018\/03\/build-rest-web-service-using-spring-boot.html","title":{"rendered":"Build REST Web Service using Spring Boot"},"content":{"rendered":"<p>This tutorial provides a step-by-step guide on how to build a restfull web service using <a href=\"https:\/\/www.javacodegeeks.com\/2014\/07\/springboot-introducing-springboot.html\">Spring Boot<\/a>.<\/p>\n<p><strong>Prerequisites:<\/strong><\/p>\n<ul>\n<li>Eclipse IDE (neon release)<\/li>\n<li>Maven 4<\/li>\n<li>Java 1.8<\/li>\n<\/ul>\n<h3>1. Create maven web project<\/h3>\n<p>Open eclipse then create a new\u00a0<a href=\"http:\/\/programmergate.com\/create-web-project-using-maven-eclipse\/\">maven web project<\/a>\u00a0and name it as\u00a0<strong><em>SpringBootRest.<\/em><\/strong><\/p>\n<p>The structure of the generated project looks like the following:<a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/03\/SpringBootRest.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-74705\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/03\/SpringBootRest.png\" alt=\"\" width=\"289\" height=\"199\" \/><\/a><\/p>\n<h3>2. pom.xml<\/h3>\n<p>After creating the web project, the first step is to configure\u00a0<strong><em>Spring Boot<\/em><\/strong>\u00a0inside\u00a0<em>pom.xml<\/em>, so we add the following as a parent dependency:<\/p>\n<pre class=\"brush:xml\">&lt;parent&gt;\r\n        &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\r\n        &lt;artifactId&gt;spring-boot-starter-parent&lt;\/artifactId&gt;\r\n        &lt;version&gt;1.5.10.RELEASE&lt;\/version&gt;\r\n&lt;\/parent&gt;<\/pre>\n<p>Spring Boot exposes a starter dependency called <em><strong>spring-boot-starter-web<\/strong><\/em> which automatically imports all the required jars needed to develop and expose REST controllers. So we add it as a dependency:<\/p>\n<pre class=\"brush:xml\">&lt;dependency&gt;\r\n    &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\r\n    &lt;artifactId&gt;spring-boot-starter-web&lt;\/artifactId&gt;\r\n&lt;\/dependency&gt;<\/pre>\n<p>In this tutorial, we use the embedded tomcat provided by Spring Boot, so we\u2019re gonna build our application as a runnable jar file by setting the <em>packaging<\/em> attribute as jar:<\/p>\n<pre class=\"brush:xml\">&lt;packaging&gt;jar&lt;\/packaging&gt;<\/pre>\n<p><em>P.S: in case you want to use external tomcat refer to <a href=\"http:\/\/programmergate.com\/deploy-spring-boot-application-external-tomcat\/\">\u201cDeploy Spring Boot application on external tomcat\u201d<\/a>.<\/em><\/p>\n<p>The final configuration step is add the Spring Boot plugin:<\/p>\n<pre class=\"brush:xml\">&lt;build&gt;\r\n        &lt;plugins&gt;\r\n            &lt;plugin&gt;\r\n                &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\r\n                &lt;artifactId&gt;spring-boot-maven-plugin&lt;\/artifactId&gt;\r\n            &lt;\/plugin&gt;\r\n        &lt;\/plugins&gt;\r\n&lt;\/build&gt;<\/pre>\n<p>Literally, that\u2019s all we need to start developing our REST controllers.<\/p>\n<p>Following are the jars automatically imported by Spring Boot:<a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/03\/SBRestDep.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-74707\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/03\/SBRestDep.png\" alt=\"\" width=\"259\" height=\"559\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/03\/SBRestDep.png 259w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/03\/SBRestDep-139x300.png 139w\" sizes=\"(max-width: 259px) 100vw, 259px\" \/><\/a><\/p>\n<p>This is the whole <strong><em>pom.xml<\/em><\/strong> for reference:<\/p>\n<pre class=\"brush:xml\">&lt;project xmlns=\"http:\/\/maven.apache.org\/POM\/4.0.0\" xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\r\n  xsi:schemaLocation=\"http:\/\/maven.apache.org\/POM\/4.0.0 http:\/\/maven.apache.org\/maven-v4_0_0.xsd\"&gt;\r\n  &lt;modelVersion&gt;4.0.0&lt;\/modelVersion&gt;\r\n  &lt;groupId&gt;com.programmer.gate&lt;\/groupId&gt;\r\n  &lt;artifactId&gt;SpringBootRest&lt;\/artifactId&gt;\r\n  &lt;packaging&gt;jar&lt;\/packaging&gt;\r\n  &lt;version&gt;0.0.1-SNAPSHOT&lt;\/version&gt;\r\n  &lt;name&gt;SpringBootRest&lt;\/name&gt;\r\n  \r\n   &lt;properties&gt;\r\n       &lt;maven.compiler.source&gt;1.8&lt;\/maven.compiler.source&gt;\r\n       &lt;maven.compiler.target&gt;1.8&lt;\/maven.compiler.target&gt;\r\n    &lt;\/properties&gt;\r\n    \r\n    &lt;parent&gt;\r\n        &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\r\n        &lt;artifactId&gt;spring-boot-starter-parent&lt;\/artifactId&gt;\r\n        &lt;version&gt;1.5.10.RELEASE&lt;\/version&gt;\r\n    &lt;\/parent&gt;\r\n    \r\n  &lt;dependencies&gt;\r\n        &lt;dependency&gt;\r\n                &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\r\n                &lt;artifactId&gt;spring-boot-starter-web&lt;\/artifactId&gt;\r\n        &lt;\/dependency&gt;\r\n  &lt;\/dependencies&gt;\r\n  \r\n  &lt;build&gt;\r\n        &lt;plugins&gt;\r\n            &lt;plugin&gt;\r\n                &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\r\n                &lt;artifactId&gt;spring-boot-maven-plugin&lt;\/artifactId&gt;\r\n            &lt;\/plugin&gt;\r\n        &lt;\/plugins&gt;\r\n    &lt;\/build&gt;\r\n&lt;\/project&gt;<\/pre>\n<h3>3. Application.java<\/h3>\n<p>The second step is to create the Spring Boot initializer class, this is the entry point of our application. Annotating a class with\u00a0<strong><em>@SpringBootApplication <\/em><\/strong>is equivalent to using <strong><em>@Configuration, @EnableAutoConfiguration and @ComponentScan<\/em><\/strong> with their default attributes in the traditional Spring applications.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\"brush:java\">package com.programmer.gate;\r\n \r\nimport org.springframework.boot.SpringApplication;\r\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\r\n \r\n@SpringBootApplication\r\npublic class Application{\r\n \r\n    public static void main(String[] args) {\r\n        SpringApplication.run(Application.class, args);\r\n    }\r\n}<\/pre>\n<p><em>P.S: By default, the servlet container automatically scans for REST controllers defined in the same package of the initializer, any controllers defined outside the package would be ignored.<\/em><\/p>\n<h3>4. Implement REST resources<\/h3>\n<p>We\u2019re going to implement a very basic payment API which charges customers for buying items.<\/p>\n<p>Our API would only accept\u00a0<em>JSON<\/em>\u00a0requests and respond back with\u00a0<em>JSON<\/em>\u00a0responses, thanks to\u00a0<em>jackson<\/em>\u00a0library which allows us to deal with requests and responses as\u00a0<em>POJO<\/em>\u00a0classes without worrying about\u00a0<em>JSON\/POJO<\/em>conversions.<\/p>\n<p>Following is the payment request class which should be submitted by clients on each payment request:<\/p>\n<pre class=\"brush:java\">package com.programmer.gate;\r\n \r\npublic class PaymentRequest {\r\n \r\n    private int userId;\r\n    private String itemId;\r\n    private double discount;\r\n \r\n    public String getItemId() {\r\n        return itemId;\r\n    }\r\n \r\n    public void setItemId(String itemId) {\r\n        this.itemId = itemId;\r\n    }\r\n \r\n    public double getDiscount() {\r\n        return discount;\r\n    }\r\n \r\n    public void setDiscount(double discount) {\r\n        this.discount = discount;\r\n    }\r\n \r\n    public int getUserId() {\r\n        return userId;\r\n    }\r\n \r\n    public void setUserId(int userId) {\r\n        this.userId = userId;\r\n    }\r\n \r\n}<\/pre>\n<p>And this is the base response returned back from our service:<\/p>\n<pre class=\"brush:java\">package com.programmer.gate;\r\n \r\npublic class BaseResponse {\r\n \r\n    private String status;\r\n    private Integer code;\r\n \r\n    public String getStatus() {\r\n        return status;\r\n    }\r\n \r\n    public void setStatus(String status) {\r\n        this.status = status;\r\n    }\r\n \r\n    public Integer getCode() {\r\n        return code;\r\n    }\r\n \r\n    public void setCode(Integer code) {\r\n        this.code = code;\r\n    }\r\n \r\n}<\/pre>\n<p>Now we define our controller named as <strong><em>PaymentController <\/em><\/strong>under <em>com.programmer.gate<\/em><strong><em>:<\/em><\/strong><\/p>\n<pre class=\"brush:java\">package com.programmer.gate;\r\n \r\nimport org.springframework.web.bind.annotation.RequestBody;\r\nimport org.springframework.web.bind.annotation.RequestMapping;\r\nimport org.springframework.web.bind.annotation.RequestMethod;\r\nimport org.springframework.web.bind.annotation.RequestParam;\r\nimport org.springframework.web.bind.annotation.RestController;\r\n \r\n@RestController\r\n@RequestMapping(\"\/payment\")\r\npublic class PaymentController {\r\n    \r\n    private final String sharedKey = \"SHARED_KEY\";\r\n    \r\n    private static final String SUCCESS_STATUS = \"success\";\r\n    private static final String ERROR_STATUS = \"error\";\r\n    private static final int CODE_SUCCESS = 100;\r\n    private static final int AUTH_FAILURE = 102;\r\n \r\n    @RequestMapping(value = \"\/pay\", method = RequestMethod.POST)\r\n    public BaseResponse pay(@RequestParam(value = \"key\") String key, @RequestBody PaymentRequest request) {\r\n        \r\n        BaseResponse response = new BaseResponse();\r\n        if(sharedKey.equalsIgnoreCase(key))\r\n        {\r\n            int userId = request.getUserId();\r\n            String itemId = request.getItemId();\r\n            double discount = request.getDiscount();\r\n            \r\n            \/\/ Process the request\r\n            \/\/ ....\r\n            \/\/ Return success response to the client.\r\n            \r\n            response.setStatus(SUCCESS_STATUS);\r\n            response.setCode(CODE_SUCCESS);\r\n        }\r\n        else\r\n        {\r\n            response.setStatus(ERROR_STATUS);\r\n            response.setCode(AUTH_FAILURE);\r\n        }\r\n        return response;\r\n    }\r\n}<\/pre>\n<p>The only service exposed by our controller is the\u00a0<em>pay()<\/em>\u00a0method which looks very straightforward, it validates the client request using a predefined shared key, processes the request and respond back with the operation status.<\/p>\n<p>Following are the common annotations used by our controller:<\/p>\n<ul>\n<li><strong><em>@RestController:<\/em><\/strong>\u00a0this annotation marks the class as a\u00a0<em>Resource,<\/em>\u00a0it defines implicitly both\u00a0<strong><em>@Controller<\/em><\/strong>\u00a0and\u00a0<strong><em>@ResponseBody<\/em><\/strong>\u00a0mvc annotations, when annotating a class with\u00a0<strong><em>@RestController,<\/em><\/strong>\u00a0it\u2019s not necessary to write\u00a0<strong><em>@ResponseBody<\/em><\/strong>\u00a0beside the\u00a0<em>POJO<\/em>\u00a0classes returned from your methods.<\/li>\n<li><strong><em>@RequestMapping:<\/em><\/strong>\u00a0this annotation defines the url of the resource in addition to the method type:\u00a0<em>GET\/POST<\/em>, in our example we expose the payment service as\u00a0<em>POST\u00a0<\/em>which is accessed through<em>\/payment\/pay.<\/em><\/li>\n<li><strong><em>@RequestParam:<\/em><\/strong>\u00a0this annotation represents a specific request parameter, in our example, we map a request parameter called\u00a0<em>key<\/em>\u00a0to an argument\u00a0<em>key<\/em>\u00a0of type\u00a0<em>String.<\/em><\/li>\n<li><strong><em>@RequestBody:<\/em><\/strong>\u00a0this annotation represents the body of the request, in our example, we map the body of the request to a\u00a0<em>POJO<\/em>\u00a0class of type\u00a0<strong><em>PaymentRequest\u00a0<\/em><\/strong><em>(jackson handles the JSON\/POJO conversion)<\/em><\/li>\n<\/ul>\n<p>As noticed the response is represented as\u00a0<strong><em>BaseResponse<\/em><\/strong>\u00a0and there is no need to annotate it,\u00a0<em>jackson<\/em>\u00a0converts it implicitly to\u00a0<em>JSON.<\/em><\/p>\n<h3>5. Deploy the application<\/h3>\n<p>Following are the steps to deploy our application:<\/p>\n<ul>\n<li><em>Right click\u00a0<strong>pom.xml<\/strong>\u00a0-&gt; run-as -&gt; Maven install<\/em><\/li>\n<li>Maven generates a jar file called <strong><em>SpringBootRest-0.0.1-SNAPSHOT.jar<\/em><\/strong>\u00a0inside target folder<\/li>\n<li>Open cmd, then run the jar using:\u00a0<em>java -jar SpringBootRest-0.0.1-SNAPSHOT.jar<\/em><\/li>\n<\/ul>\n<p>Here we go, our application is up and ready to serve requests at the default port\u00a0<strong><em>8080<\/em><\/strong>.<\/p>\n<h3>6. Test the service<\/h3>\n<p>In order to test our API, we use\u00a0<em>Advanced REST client<\/em>\u00a0plugin from chrome and we initiate 2 different requests:<\/p>\n<p><em>Successful request:<\/em>\u00a0in this request we pass a valid shared key as a request parameter along with item details in the request body. This is how it looks like:<a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/03\/SBRequest.png\"><img decoding=\"async\" class=\"aligncenter wp-image-74708\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/03\/SBRequest.png\" alt=\"\" width=\"860\" height=\"505\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/03\/SBRequest.png 987w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/03\/SBRequest-300x176.png 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/03\/SBRequest-768x451.png 768w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><\/p>\n<p>And this is our response:<\/p>\n<pre class=\"brush:java\">{\r\n      \"status\": \"success\",\r\n      \"code\": 100\r\n}<\/pre>\n<p><em>Failure request:<\/em>\u00a0this request looks similar to the above but with invalid shared key, this is what we get from our API:<\/p>\n<pre class=\"brush:java\">{\r\n     \"status\": \"error\",\r\n     \"code\": 102\r\n}<\/pre>\n<p>That\u2019s it, hope you find it useful.<\/p>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td>Published on Java Code Geeks with permission by Hussein Terek, partner at our <a href=\"\/\/www.javacodegeeks.com\/join-us\/jcg\/\" target=\"_blank\" rel=\"noopener\">JCG program<\/a>. See the original article here: <a href=\"http:\/\/programmergate.com\/build-rest-web-service-using-spring-boot\/\" target=\"_blank\" rel=\"noopener\">Build REST Web Service using Spring Boot<\/a><\/p>\n<p>Opinions expressed by Java Code Geeks contributors are their own.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial provides a step-by-step guide on how to build a restfull web service using Spring Boot. Prerequisites: Eclipse IDE (neon release) Maven 4 Java 1.8 1. Create maven web project Open eclipse then create a new\u00a0maven web project\u00a0and name it as\u00a0SpringBootRest. The structure of the generated project looks like the following: 2. pom.xml After &hellip;<\/p>\n","protected":false},"author":22157,"featured_media":240,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[670,815,30,854,679,1706],"class_list":["post-74701","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-maven","tag-rest","tag-spring","tag-spring-boot","tag-tomcat","tag-webservice"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Build REST Web Service using Spring Boot - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"This tutorial provides a step-by-step guide on how to build a restfull web service using Spring Boot. Prerequisites: Eclipse IDE (neon release) Maven 4\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2018\/03\/build-rest-web-service-using-spring-boot.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Build REST Web Service using Spring Boot - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"This tutorial provides a step-by-step guide on how to build a restfull web service using Spring Boot. Prerequisites: Eclipse IDE (neon release) Maven 4\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2018\/03\/build-rest-web-service-using-spring-boot.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2018-03-13T05:00:39+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Hussein Terek\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@houssein_terek\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Hussein Terek\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/03\\\/build-rest-web-service-using-spring-boot.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/03\\\/build-rest-web-service-using-spring-boot.html\"},\"author\":{\"name\":\"Hussein Terek\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/605b45976369716cff1bc2f6aa321f5f\"},\"headline\":\"Build REST Web Service using Spring Boot\",\"datePublished\":\"2018-03-13T05:00:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/03\\\/build-rest-web-service-using-spring-boot.html\"},\"wordCount\":748,\"commentCount\":5,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/03\\\/build-rest-web-service-using-spring-boot.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"keywords\":[\"Maven\",\"REST\",\"Spring\",\"Spring Boot\",\"Tomcat\",\"webservice\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/03\\\/build-rest-web-service-using-spring-boot.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/03\\\/build-rest-web-service-using-spring-boot.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/03\\\/build-rest-web-service-using-spring-boot.html\",\"name\":\"Build REST Web Service using Spring Boot - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/03\\\/build-rest-web-service-using-spring-boot.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/03\\\/build-rest-web-service-using-spring-boot.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"datePublished\":\"2018-03-13T05:00:39+00:00\",\"description\":\"This tutorial provides a step-by-step guide on how to build a restfull web service using Spring Boot. Prerequisites: Eclipse IDE (neon release) Maven 4\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/03\\\/build-rest-web-service-using-spring-boot.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/03\\\/build-rest-web-service-using-spring-boot.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/03\\\/build-rest-web-service-using-spring-boot.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"spring-interview-questions-answers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/03\\\/build-rest-web-service-using-spring-boot.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Build REST Web Service using Spring Boot\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/605b45976369716cff1bc2f6aa321f5f\",\"name\":\"Hussein Terek\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4a5cdbad7c8bc5d99a9bdc62ee9d16b31a2302627f1ebffd3a616e6554bf3ba9?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4a5cdbad7c8bc5d99a9bdc62ee9d16b31a2302627f1ebffd3a616e6554bf3ba9?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4a5cdbad7c8bc5d99a9bdc62ee9d16b31a2302627f1ebffd3a616e6554bf3ba9?s=96&d=mm&r=g\",\"caption\":\"Hussein Terek\"},\"description\":\"Hussein is a senior software engineer with 5 years of experience in software design, development and integration. He is the author and founder of Programmer Gate (www.programmergate.com) blog.\",\"sameAs\":[\"http:\\\/\\\/programmergate.com\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/hussein-terek-2843aa66\\\/\",\"https:\\\/\\\/x.com\\\/houssein_terek\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/hussein-terek\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Build REST Web Service using Spring Boot - Java Code Geeks","description":"This tutorial provides a step-by-step guide on how to build a restfull web service using Spring Boot. Prerequisites: Eclipse IDE (neon release) Maven 4","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2018\/03\/build-rest-web-service-using-spring-boot.html","og_locale":"en_US","og_type":"article","og_title":"Build REST Web Service using Spring Boot - Java Code Geeks","og_description":"This tutorial provides a step-by-step guide on how to build a restfull web service using Spring Boot. Prerequisites: Eclipse IDE (neon release) Maven 4","og_url":"https:\/\/www.javacodegeeks.com\/2018\/03\/build-rest-web-service-using-spring-boot.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2018-03-13T05:00:39+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","type":"image\/jpeg"}],"author":"Hussein Terek","twitter_card":"summary_large_image","twitter_creator":"@houssein_terek","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Hussein Terek","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2018\/03\/build-rest-web-service-using-spring-boot.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/03\/build-rest-web-service-using-spring-boot.html"},"author":{"name":"Hussein Terek","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/605b45976369716cff1bc2f6aa321f5f"},"headline":"Build REST Web Service using Spring Boot","datePublished":"2018-03-13T05:00:39+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/03\/build-rest-web-service-using-spring-boot.html"},"wordCount":748,"commentCount":5,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/03\/build-rest-web-service-using-spring-boot.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","keywords":["Maven","REST","Spring","Spring Boot","Tomcat","webservice"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2018\/03\/build-rest-web-service-using-spring-boot.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2018\/03\/build-rest-web-service-using-spring-boot.html","url":"https:\/\/www.javacodegeeks.com\/2018\/03\/build-rest-web-service-using-spring-boot.html","name":"Build REST Web Service using Spring Boot - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/03\/build-rest-web-service-using-spring-boot.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/03\/build-rest-web-service-using-spring-boot.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","datePublished":"2018-03-13T05:00:39+00:00","description":"This tutorial provides a step-by-step guide on how to build a restfull web service using Spring Boot. Prerequisites: Eclipse IDE (neon release) Maven 4","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/03\/build-rest-web-service-using-spring-boot.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2018\/03\/build-rest-web-service-using-spring-boot.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2018\/03\/build-rest-web-service-using-spring-boot.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","width":150,"height":150,"caption":"spring-interview-questions-answers"},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2018\/03\/build-rest-web-service-using-spring-boot.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Build REST Web Service using Spring Boot"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/605b45976369716cff1bc2f6aa321f5f","name":"Hussein Terek","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4a5cdbad7c8bc5d99a9bdc62ee9d16b31a2302627f1ebffd3a616e6554bf3ba9?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4a5cdbad7c8bc5d99a9bdc62ee9d16b31a2302627f1ebffd3a616e6554bf3ba9?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4a5cdbad7c8bc5d99a9bdc62ee9d16b31a2302627f1ebffd3a616e6554bf3ba9?s=96&d=mm&r=g","caption":"Hussein Terek"},"description":"Hussein is a senior software engineer with 5 years of experience in software design, development and integration. He is the author and founder of Programmer Gate (www.programmergate.com) blog.","sameAs":["http:\/\/programmergate.com\/","https:\/\/www.linkedin.com\/in\/hussein-terek-2843aa66\/","https:\/\/x.com\/houssein_terek"],"url":"https:\/\/www.javacodegeeks.com\/author\/hussein-terek"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/74701","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/22157"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=74701"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/74701\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/240"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=74701"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=74701"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=74701"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}