forked from spring-guides/gs-rest-service
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
apply plugin: 'java' | ||
apply plugin: 'jetty' | ||
apply plugin: 'eclipse-wtp' | ||
|
||
repositories { mavenCentral() } | ||
|
||
dependencies { | ||
compile "org.springframework:spring-webmvc:3.2.2.RELEASE" | ||
compile "org.codehaus.jackson:jackson-mapper-asl:1.9.9" | ||
} | ||
|
||
task wrapper(type: Wrapper) { | ||
gradleVersion = '1.5' | ||
} |
23 changes: 23 additions & 0 deletions
23
hello-world-rest/src/main/java/org/springframework/hello/HelloWorldResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.springframework.hello; | ||
|
||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
|
||
@Controller | ||
@RequestMapping("/hello-world") | ||
public class HelloWorldResource { | ||
|
||
private static final String template = "Hello, %s!"; | ||
private final AtomicLong counter = new AtomicLong(); | ||
|
||
@RequestMapping(method=RequestMethod.GET) | ||
public @ResponseBody Saying sayHello(@RequestParam(value="name", required=false, defaultValue="Stranger") String name) { | ||
return new Saying(counter.incrementAndGet(), String.format(template, name)); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
hello-world-rest/src/main/java/org/springframework/hello/Saying.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.springframework.hello; | ||
|
||
public class Saying { | ||
|
||
private final long id; | ||
private final String content; | ||
|
||
public Saying(long id, String content) { | ||
this.id = id; | ||
this.content = content; | ||
} | ||
|
||
public long getId() { | ||
return id; | ||
} | ||
|
||
public String getContent() { | ||
return content; | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
hello-world-rest/src/main/java/org/springframework/hello/config/HelloWorldConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.springframework.hello.config; | ||
|
||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.ComponentScan.Filter; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.servlet.config.annotation.EnableWebMvc; | ||
|
||
@Configuration | ||
@EnableWebMvc | ||
@ComponentScan(basePackages="org.springframework.hello", excludeFilters=@Filter(Configuration.class)) | ||
public class HelloWorldConfiguration { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> | ||
|
||
<!-- Java-based annotation-driven Spring container definition --> | ||
<context-param> | ||
<param-name>contextClass</param-name> | ||
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value> | ||
</context-param> | ||
|
||
<!-- Location of Java @Configuration classes that configure the components that makeup this application --> | ||
<context-param> | ||
<param-name>contextConfigLocation</param-name> | ||
<param-value>org.springframework.hello.config</param-value> | ||
</context-param> | ||
|
||
<!-- Creates the Spring Container shared by all Servlets and Filters --> | ||
<listener> | ||
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> | ||
</listener> | ||
|
||
<!-- Processes application requests --> | ||
<servlet> | ||
<servlet-name>appServlet</servlet-name> | ||
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> | ||
<init-param> | ||
<param-name>contextClass</param-name> | ||
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value> | ||
</init-param> | ||
<init-param> | ||
<param-name>contextConfigLocation</param-name> | ||
<param-value>org.springframework.hello.config</param-value> | ||
</init-param> | ||
<load-on-startup>1</load-on-startup> | ||
</servlet> | ||
|
||
<servlet-mapping> | ||
<servlet-name>appServlet</servlet-name> | ||
<url-pattern>/</url-pattern> | ||
</servlet-mapping> | ||
|
||
</web-app> |