#
Create client for REST Server
Spring Boot is designed to speed up the development of Spring applications by writing less boilerplate code. Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run". Most Spring Boot applications need very little Spring configuration.
In this tutorial I will create a Spring Boot REST Web Service Client (Consumer).
First of all, you need to (1) create a simple Spring Application configured with Maven. After that you need to configure (2) Maven using pom.xml file .
Here is the POM configuration for a simple Spring Boot REST Web Service Client (Consumer):
After that you have to add the following classes to the Spring Boot REST Web Client Application :
package com.example.main;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class Student {
String name;
int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
package com.example.main;
import org.springframework.web.client.RestTemplate;
public class Main {
public static void main (String [] args) {
RestTemplate restTemplate = new RestTemplate();
Student student = restTemplate.getForObject("http://localhost:8080/student/Dan/20", Student.class);
System.out.println(student.name);
System.out.println(student.age);
String response2
= restTemplate.getForObject("http://localhost:8080/add?value1=1&value2=10", String.class);
System.out.println(response2);
}
}
When we run the Spring Boot REST Web Service Client we receive the following output: