Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- buildscript{
- repositories{
- mavenCentral()
- }
- dependencies{
- classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.3.RELEASE")
- }
- }
- apply plugin: 'java'
- apply plugin: 'eclipse'
- apply plugin: 'idea'
- apply plugin: 'spring-boot'
- jar{
- baseName = 'gs-rest-service'
- version = '0.1.0'
- }
- repositories{
- mavenCentral()
- }
- sourceCompatibility = 1.8
- targetCompatibility = 1.8
- dependencies{
- compile("org.springframework.boot:spring-boot-starter-web")
- testCompile("junit:junit")
- }
- task wrapper(type: Wrapper){
- gradleVersion = '2.3'
- }
- package hello;
- import org.springframework.boot.SpringApplication;
- import org.springframework.boot.autoconfigure.SpringBootApplication;
- @SpringBootApplication
- public class Application {
- public static void main(String[] args) {
- SpringApplication.run(Application.class, args);
- }
- }
- package hello;
- public class Greeting {
- private final long id;
- private final String content;
- public Greeting(long id, String content) {
- super();
- this.id = id;
- this.content = content;
- }
- public long getId() {
- return id;
- }
- public String getContent() {
- return content;
- }
- }
- 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", defaultValue = "World") String name) {
- return new Greeting(counter.incrementAndGet(), String.format(template, name));
- }
- }
- 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;
- }
- }
- 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", defaultValue="World") String name) {
- return new Greeting(counter.incrementAndGet(),
- String.format(template, name));
- }
- }
- package hello;
- import org.springframework.boot.SpringApplication;
- import org.springframework.boot.autoconfigure.SpringBootApplication;
- @SpringBootApplication
- public class GsRestServiceApplication {
- public static void main(String[] args) {
- SpringApplication.run(GreetingController.class, args); // <-- modify this line.
- }
- }
- package hello;
- import org.springframework.boot.builder.SpringApplicationBuilder;
- import org.springframework.boot.context.web.SpringBootServletInitializer;
- public class ServletInitializer extends SpringBootServletInitializer {
- @Override
- protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
- return application.sources(GsRestServiceApplication.class);
- }
- }
- http://localhost:8080/gs-rest-service/greeting?name=Vy
- dependencies {
- providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
- }
- compile("org.springframework.boot:spring-boot-starter-web")
- <packaging>war</packaging>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-tomcat</artifactId>
- <scope>provided</scope>
- </dependency>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement