소스 검색

Added sample project

Craig Walls 13 년 전
부모
커밋
82b17e6804

+ 14
- 0
hello-world-rest/build.gradle 파일 보기

@@ -0,0 +1,14 @@
1
+apply plugin: 'java'
2
+apply plugin: 'jetty'
3
+apply plugin: 'eclipse-wtp'
4
+
5
+repositories { mavenCentral() }
6
+
7
+dependencies {
8
+	compile "org.springframework:spring-webmvc:3.2.2.RELEASE"
9
+	compile "org.codehaus.jackson:jackson-mapper-asl:1.9.9"
10
+}
11
+
12
+task wrapper(type: Wrapper) {
13
+	gradleVersion = '1.5'
14
+}

+ 23
- 0
hello-world-rest/src/main/java/org/springframework/hello/HelloWorldResource.java 파일 보기

@@ -0,0 +1,23 @@
1
+package org.springframework.hello;
2
+
3
+import java.util.concurrent.atomic.AtomicLong;
4
+
5
+import org.springframework.stereotype.Controller;
6
+import org.springframework.web.bind.annotation.RequestMapping;
7
+import org.springframework.web.bind.annotation.RequestMethod;
8
+import org.springframework.web.bind.annotation.RequestParam;
9
+import org.springframework.web.bind.annotation.ResponseBody;
10
+
11
+@Controller
12
+@RequestMapping("/hello-world")
13
+public class HelloWorldResource {
14
+  
15
+  private static final String template = "Hello, %s!";
16
+  private final AtomicLong counter = new AtomicLong();
17
+
18
+	@RequestMapping(method=RequestMethod.GET)
19
+	public @ResponseBody Saying sayHello(@RequestParam(value="name", required=false, defaultValue="Stranger") String name) {
20
+		return new Saying(counter.incrementAndGet(), String.format(template, name));
21
+	}
22
+	
23
+}

+ 21
- 0
hello-world-rest/src/main/java/org/springframework/hello/Saying.java 파일 보기

@@ -0,0 +1,21 @@
1
+package org.springframework.hello;
2
+
3
+public class Saying {
4
+
5
+  private final long id;
6
+  private final String content;
7
+
8
+  public Saying(long id, String content) {
9
+    this.id = id;
10
+    this.content = content;
11
+  }
12
+
13
+  public long getId() {
14
+    return id;
15
+  }
16
+
17
+  public String getContent() {
18
+    return content;
19
+  }
20
+
21
+}

+ 12
- 0
hello-world-rest/src/main/java/org/springframework/hello/config/HelloWorldConfiguration.java 파일 보기

@@ -0,0 +1,12 @@
1
+package org.springframework.hello.config;
2
+
3
+import org.springframework.context.annotation.ComponentScan;
4
+import org.springframework.context.annotation.ComponentScan.Filter;
5
+import org.springframework.context.annotation.Configuration;
6
+import org.springframework.web.servlet.config.annotation.EnableWebMvc;
7
+
8
+@Configuration
9
+@EnableWebMvc
10
+@ComponentScan(basePackages="org.springframework.hello", excludeFilters=@Filter(Configuration.class))
11
+public class HelloWorldConfiguration {
12
+}

+ 43
- 0
hello-world-rest/src/main/webapp/WEB-INF/web.xml 파일 보기

@@ -0,0 +1,43 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
3
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
5
+
6
+	<!-- Java-based annotation-driven Spring container definition -->
7
+	<context-param>
8
+		<param-name>contextClass</param-name>
9
+		<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
10
+	</context-param>
11
+
12
+	<!-- Location of Java @Configuration classes that configure the components that makeup this application -->
13
+	<context-param>
14
+		<param-name>contextConfigLocation</param-name>
15
+		<param-value>org.springframework.hello.config</param-value>
16
+	</context-param>
17
+	
18
+	<!-- Creates the Spring Container shared by all Servlets and Filters -->
19
+	<listener>
20
+		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
21
+	</listener>
22
+
23
+	<!-- Processes application requests -->
24
+	<servlet>
25
+		<servlet-name>appServlet</servlet-name>
26
+		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
27
+		<init-param>
28
+			<param-name>contextClass</param-name>
29
+			<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
30
+		</init-param>
31
+		<init-param>
32
+			<param-name>contextConfigLocation</param-name>
33
+			<param-value>org.springframework.hello.config</param-value>
34
+		</init-param>
35
+		<load-on-startup>1</load-on-startup>
36
+	</servlet>
37
+		
38
+	<servlet-mapping>
39
+		<servlet-name>appServlet</servlet-name>
40
+		<url-pattern>/</url-pattern>
41
+	</servlet-mapping>
42
+
43
+</web-app>