Skip to content

Commit

Permalink
Added sample project
Browse files Browse the repository at this point in the history
  • Loading branch information
habuma committed Apr 15, 2013
1 parent 741fd0d commit 82b17e6
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 0 deletions.
14 changes: 14 additions & 0 deletions hello-world-rest/build.gradle
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'
}
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));
}

}
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;
}

}
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 {
}
43 changes: 43 additions & 0 deletions hello-world-rest/src/main/webapp/WEB-INF/web.xml
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>

0 comments on commit 82b17e6

Please sign in to comment.