Last active
August 29, 2015 13:57
-
-
Save siguremon/9350050 to your computer and use it in GitHub Desktop.
Spring3のSpring MVCでなるべく最小単位のHello world ref: http://qiita.com/siguremon/items/84c831391a6204079fd2
This file contains hidden or 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
<?xml version="1.0" encoding="UTF-8"?> | |
<beans xmlns="http://www.springframework.org/schema/beans" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xmlns:context="http://www.springframework.org/schema/context" | |
xmlns:mvc="http://www.springframework.org/schema/mvc" | |
xsi:schemaLocation=" | |
http://www.springframework.org/schema/beans | |
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd | |
http://www.springframework.org/schema/context | |
http://www.springframework.org/schema/context/spring-context-3.1.xsd | |
http://www.springframework.org/schema/mvc | |
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd"> | |
<!-- (1) --> | |
<context:component-scan base-package="controller" /> | |
<!-- (2) --> | |
<mvc:annotation-driven /> | |
<!-- (3) --> | |
<mvc:resources mapping="/resources/**" location="/WEB-INF/resources/" /> | |
<!-- (4) --> | |
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> | |
<property name="prefix" value="/WEB-INF/views/" /> | |
<property name="suffix" value=".jsp" /> | |
</bean> | |
</beans> |
This file contains hidden or 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
SpringTodo | |
|-pom.xml | |
|-src | |
|-main | |
| |-java | |
| | |-controller | |
| | |-HelloWorldController.java -- Controllerクラス | |
| |-resources | |
| | |-META-INF -- Spring周りの設定ファイルおよびリソースファイルを配置するフォルダ | |
| | |-spring | |
| | |-beans-webmvc.xml -- Spring MVCのBean定義ファイル | |
| |-webapp -- Web Application周りのファイルを配置するフォルダ | |
| |-WEB-INF | |
| |-web.xml | |
| |-resources -- 静的リソースを配置するフォルダ | |
| |-views -- jspなどのviewを配置するフォルダ | |
| |-helloworld.jsp | |
|-test | |
This file contains hidden or 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
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> | |
<h1>hello world</h1> |
This file contains hidden or 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 controller; | |
import static org.springframework.web.bind.annotation.RequestMethod.GET; | |
import org.springframework.stereotype.Controller; | |
import org.springframework.web.bind.annotation.RequestMapping; | |
// (1) | |
@Controller | |
public class HelloWorldController { | |
// (2) | |
@RequestMapping(value = "/", method = GET) | |
public String home() { | |
// (3) | |
return "helloworld"; | |
} | |
} |
This file contains hidden or 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
<?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 | |
"> | |
<display-name>spring-todo</display-name> | |
<!-- (1) --> | |
<servlet> | |
<servlet-name>dispatcherServlet</servlet-name> | |
<servlet-class> | |
org.springframework.web.servlet.DispatcherServlet | |
</servlet-class> | |
<init-param> | |
<param-name>contextConfigLocation</param-name> | |
<param-value> | |
classpath:/META-INF/spring/beans-webmvc.xml | |
</param-value> | |
</init-param> | |
<load-on-startup>1</load-on-startup> | |
</servlet> | |
<!-- (2) --> | |
<servlet-mapping> | |
<servlet-name>dispatcherServlet</servlet-name> | |
<url-pattern>/</url-pattern> | |
</servlet-mapping> | |
</web-app> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment