Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 KB | None | 0 0
  1. buildscript{
  2. repositories{
  3. mavenCentral()
  4. }
  5. dependencies{
  6. classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.3.RELEASE")
  7. }
  8. }
  9.  
  10. apply plugin: 'java'
  11. apply plugin: 'eclipse'
  12. apply plugin: 'idea'
  13. apply plugin: 'spring-boot'
  14.  
  15. jar{
  16. baseName = 'gs-rest-service'
  17. version = '0.1.0'
  18. }
  19.  
  20. repositories{
  21. mavenCentral()
  22. }
  23.  
  24. sourceCompatibility = 1.8
  25. targetCompatibility = 1.8
  26.  
  27. dependencies{
  28. compile("org.springframework.boot:spring-boot-starter-web")
  29. testCompile("junit:junit")
  30. }
  31. task wrapper(type: Wrapper){
  32. gradleVersion = '2.3'
  33. }
  34.  
  35. package hello;
  36.  
  37. import org.springframework.boot.SpringApplication;
  38. import org.springframework.boot.autoconfigure.SpringBootApplication;
  39.  
  40. @SpringBootApplication
  41. public class Application {
  42.  
  43. public static void main(String[] args) {
  44. SpringApplication.run(Application.class, args);
  45. }
  46.  
  47. }
  48.  
  49. package hello;
  50.  
  51. public class Greeting {
  52.  
  53. private final long id;
  54. private final String content;
  55.  
  56. public Greeting(long id, String content) {
  57. super();
  58. this.id = id;
  59. this.content = content;
  60. }
  61.  
  62. public long getId() {
  63. return id;
  64. }
  65.  
  66. public String getContent() {
  67. return content;
  68. }
  69.  
  70. }
  71.  
  72. package hello;
  73.  
  74. import java.util.concurrent.atomic.AtomicLong;
  75.  
  76. import org.springframework.web.bind.annotation.RequestMapping;
  77. import org.springframework.web.bind.annotation.RequestParam;
  78. import org.springframework.web.bind.annotation.RestController;
  79.  
  80. @RestController
  81. public class GreetingController {
  82.  
  83. private static final String template = "Hello, %s";
  84. private final AtomicLong counter = new AtomicLong();
  85.  
  86. @RequestMapping("/greeting")
  87. public Greeting greeting(@RequestParam(value = "name", defaultValue = "World") String name) {
  88. return new Greeting(counter.incrementAndGet(), String.format(template, name));
  89. }
  90.  
  91. }
  92.  
  93. package hello;
  94.  
  95. public class Greeting {
  96.  
  97. private final long id;
  98. private final String content;
  99.  
  100. public Greeting(long id, String content) {
  101. this.id = id;
  102. this.content = content;
  103. }
  104.  
  105. public long getId() {
  106. return id;
  107. }
  108.  
  109. public String getContent() {
  110. return content;
  111. }
  112. }
  113.  
  114. package hello;
  115.  
  116. import java.util.concurrent.atomic.AtomicLong;
  117. import org.springframework.web.bind.annotation.RequestMapping;
  118. import org.springframework.web.bind.annotation.RequestParam;
  119. import org.springframework.web.bind.annotation.RestController;
  120.  
  121. @RestController
  122. public class GreetingController {
  123.  
  124. private static final String template = "Hello, %s!";
  125. private final AtomicLong counter = new AtomicLong();
  126.  
  127. @RequestMapping("/greeting")
  128. public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) {
  129. return new Greeting(counter.incrementAndGet(),
  130. String.format(template, name));
  131. }
  132. }
  133.  
  134. package hello;
  135.  
  136. import org.springframework.boot.SpringApplication;
  137. import org.springframework.boot.autoconfigure.SpringBootApplication;
  138.  
  139. @SpringBootApplication
  140. public class GsRestServiceApplication {
  141.  
  142. public static void main(String[] args) {
  143. SpringApplication.run(GreetingController.class, args); // <-- modify this line.
  144. }
  145. }
  146.  
  147. package hello;
  148.  
  149. import org.springframework.boot.builder.SpringApplicationBuilder;
  150. import org.springframework.boot.context.web.SpringBootServletInitializer;
  151.  
  152. public class ServletInitializer extends SpringBootServletInitializer {
  153.  
  154. @Override
  155. protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
  156. return application.sources(GsRestServiceApplication.class);
  157. }
  158.  
  159. }
  160.  
  161. http://localhost:8080/gs-rest-service/greeting?name=Vy
  162.  
  163. dependencies {
  164. providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
  165. }
  166.  
  167. compile("org.springframework.boot:spring-boot-starter-web")
  168.  
  169. <packaging>war</packaging>
  170. <dependency>
  171. <groupId>org.springframework.boot</groupId>
  172. <artifactId>spring-boot-starter-tomcat</artifactId>
  173. <scope>provided</scope>
  174. </dependency>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement