Difference between revisions of "Spring Boot"

From air
Jump to navigation Jump to search
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
http://projects.spring.io/spring-boot/
 
http://projects.spring.io/spring-boot/
   
  +
https://spring.io/guides/gs/rest-service/
   
  +
=Very simple application=
<source language="java">
+
<source lang="java">
   
 
package hello;
 
package hello;
Line 28: Line 30:
   
 
</source>
 
</source>
  +
  +
==Getting Started==
  +
Start the Mongo DB (with [[Docker]])
  +
<pre>
  +
docker run --name mongo-for-spring -p27017:27017 -d mongo
  +
</pre>
  +
  +
Install and start the application (from https://dzone.com/articles/spring-boot-reactive-tutorial)
  +
<pre>
  +
git clone https://github.com/mohitsinha/spring-boot-webflux-reactive-mongo.git
  +
cd spring-boot-webflux-reactive-mongo/
  +
./gradlew tasks --all
  +
./gradlew bootRun
  +
</pre>
  +
  +
Invoke the RESTful service
  +
<pre>
  +
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
  +
</pre>
  +
  +
Exercice: Improve com.spring.example.controllers.RoutesConfiguration for adding the PUT (Update) verb.
  +
<pre>
  +
curl -v -X PUT -H "Content-Type: application/json" -d '{"name":"Albert Einstein","age":15, "id":"59b15b69c6f85a2e89498a16"}' http://tom:password@localhost:8080/person
  +
</pre>

Latest revision as of 16:56, 7 September 2017

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