We will walk through the minimum to set up Spring MVC on Google App Engine.
- Java 1.6
- Spring MVC 3.2
- Google App Engine SDK 1.7
- Spring Tool Suite 3.1
Launch Spring Tool Suite.
In the Dashboard (one of the tabs), click Extensions. Find and install Google Plugin.
Create a Google App Engine Project. Do not check GWT.
First put the following Spring dependencies to /war/WEB-INF/lib
- spring-aop-3.2.0.RELEASE.jar
- spring-beans-3.2.0.RELEASE.jar
- spring-context-3.2.0.RELEASE.jar
- spring-context-support-3.2.0.RELEASE.jar
- spring-core-3.2.0.RELEASE.jar
- spring-expression-3.2.0.RELEASE.jar
- spring-web-3.2.0.RELEASE.jar
- spring-webmvc-3.2.0.RELEASE.jar
You will also need:
Right click on the root folder of the project. Click Properties. Click Java Build Path. Add all the jars above.
In /war/WEB-INF/web.xml, add the following:
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
<servlet> | |
<servlet-name>spring-mvc</servlet-name> | |
<servlet-class> | |
org.springframework.web.servlet.DispatcherServlet | |
</servlet-class> | |
<load-on-startup>1</load-on-startup> | |
</servlet> | |
<servlet-mapping> | |
<servlet-name>spring-mvc</servlet-name> | |
<url-pattern>/</url-pattern> | |
</servlet-mapping> | |
<context-param> | |
<param-name>contextConfigLocation</param-name> | |
<param-value>/WEB-INF/spring-mvc-servlet.xml</param-value> | |
</context-param> | |
<listener> | |
<listener-class> | |
org.springframework.web.context.ContextLoaderListener | |
</listener-class> | |
</listener> |
Create /war/WEB-INF/spring-mvc-servlet.xml.
Replace with:
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
<bean id="VideoController" class="com.yourcompanyname.controller.HelloController" /> | |
<bean id="viewResolver" | |
class="org.springframework.web.servlet.view.InternalResourceViewResolver"> | |
<property name="prefix"> | |
<value>/views/</value> | |
</property> | |
<property name="suffix"> | |
<value>.jsp</value> | |
</property> | |
</bean> |
Create the folder /war/views.
Create the file /war/views/hello_world.jsp.
Create the file /src/com.yournamespace.controller.HelloWorldController.java
Put the following:
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
package com.yournamespace.controller; | |
import org.springframework.stereotype.Controller; | |
import org.springframework.ui.ModelMap; | |
import org.springframework.web.bind.annotation.PathVariable; | |
import org.springframework.web.bind.annotation.RequestMapping; | |
import org.springframework.web.bind.annotation.RequestMethod; | |
@RequestMapping(value="/hello") | |
public class HelloContoller { | |
@RequestMapping(value="", method = RequestMethod.GET) | |
public String sayHello() { | |
return "hello_world"; | |
} | |
} |
The above returns the hello_world.jsp.
Right click on the root project folder. Click Run as -> Web Application.
No comments:
Post a Comment