Spring Boot
Jump to navigation
Jump to search
http://projects.spring.io/spring-boot/
https://spring.io/guides/gs/rest-service/
Very simple application
package hello;
import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;
@Controller
@EnableAutoConfiguration
public class SampleController {
@RequestMapping("/")
@ResponseBody
String home() {
return "Hello World!";
}
public static void main(String[] args) throws Exception {
SpringApplication.run(SampleController.class, args);
}
}
Getting Started
Start the Mongo DB (with Docker)
docker run --name mongo-for-spring -p27017:27017 -d mongo
Install and start the application (from https://dzone.com/articles/spring-boot-reactive-tutorial)
git clone https://github.com/mohitsinha/spring-boot-webflux-reactive-mongo.git cd spring-boot-webflux-reactive-mongo/ ./gradlew tasks --all ./gradlew bootRun
Invoke the RESTful service
curl -v http://localhost:8080 curl -v http://localhost:8080/person curl -v http://tom:password@localhost:8080 curl -v http://tom:password@localhost:8080/person curl -v -X GET http://tom:password@localhost:8080/person curl -v -X POST -H "Content-Type: application/json" -d '{"name":"Issac","age":20}' http://tom:password@localhost:8080/person curl -v -X POST -H "Content-Type: application/json" -d '{"name":"Albert","age":10}' http://tom:password@localhost:8080/person curl -v -X GET http://tom:password@localhost:8080/person
Exercice: Improve com.spring.example.controllers.RoutesConfiguration for adding the PUT (Update) verb.
curl -v -X PUT -H "Content-Type: application/json" -d '{"name":"Albert Einstein","age":15, "id":"59b15b69c6f85a2e89498a16"}' http://tom:password@localhost:8080/person