= Spring =
Spring helps development teams everywhere build simple, portable, fast and flexible JVM-based systems and applications.

== REST service ==
spring.io/guides/gs/rest-service/

=== Structure ===
{{{
.
|-- pom.xml
|-- src
|   `-- main
|       `-- java
|           `-- hello
|               |-- Application.java
|               |-- Greeting.java
|               `-- GreetingController.java
`-- target
    |-- classes
    |   `-- hello
    |       |-- Application.class
    |       |-- Greeting.class
    |       `-- GreetingController.class
    |-- generated-sources
    |   `-- annotations
    |-- gs-rest-service-0.1.0.jar
    |-- gs-rest-service-0.1.0.jar.original
    `-- maven-archiver
        `-- pom.properties

}}}

=== Steps ===

 * mkdir -p /tmp/greetingSpring
 * mkdir -p /tmp/greetingSpring/src/main/java/hello
 * mkdir -p /tmp/greetingSpring/target
 * cd /tmp/greetingSpring

pom.xml 
{{{#!highlihht xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.springframework</groupId>
  <artifactId>gs-rest-service</artifactId>
  <version>0.1.0</version>
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.1.5.RELEASE</version>
  </parent>
  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
  </dependencies>
<properties>
<start-class>hello.Application</start-class>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-releases</id>
<url>http://repo.spring.io/libs-release</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-releases</id>
<url>http://repo.spring.io/libs-release</url>
</pluginRepository>
</pluginRepositories>
</project>
}}}

src/main/java/hello/Application.java 
{{{#!highlight java
package hello;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.ComponentScan;

@ComponentScan
@EnableAutoConfiguration
public class Application {

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

src/main/java/hello/Greeting.java 
{{{#!highlight java
package hello;

public class Greeting {

    private final long id;
    private final String content;

    public Greeting(long id, String content) {
        this.id = id;
        this.content = content;
    }

    public long getId() {
        return id;
    }

    public String getContent() {
        return content;
    }
}
}}}

src/main/java/hello/GreetingController.java 
{{{#!highlight java
package hello;

import java.util.concurrent.atomic.AtomicLong;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class GreetingController {

    private static final String template = "Hello, %s!";
    private final AtomicLong counter = new AtomicLong();

    @RequestMapping("/greeting")
    public Greeting greeting(@RequestParam(value="name", required=false, defaultValue="World") String name) {
        return new Greeting(counter.incrementAndGet(),
                            String.format(template, name));
    }
}

}}}

Build with 
 * mvn clean compile package

Run with:
 * jar -tf target/gs-rest-service-0.1.0.jar # check JAR contents
 * java -jar target/gs-rest-service-0.1.0.jar
 * open URL http://localhost:8080/greeting