码迷,mamicode.com
首页 > 编程语言 > 详细

Spring最简设置

时间:2016-01-23 21:27:25      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:

Sping 整合 MVN, 类注释 @Controller 方法注释: @RequestMapping("/hello") 必须。

Web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

         xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

         id="study" version="2.5">

         <display-name>Archetype Created Web Application</display-name>

         <description>sprintMVC环境搭建</description>

         <!-- 加载Spring配置文件 -->

         <context-param>

                   <param-name>contextConfigLocation</param-name>

                   <param-value>classpath:/configs/spring-*.xml</param-value>

         </context-param>

         <!-- Spring监听 -->

         <listener>

                   <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

         </listener>

         <!-- Spring MVC配置 -->

         <servlet>

                   <servlet-name>Dispatcher</servlet-name>

                   <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

                   <!-- 自定义spring mvc的配置文件名称和路径 -->

                   <init-param>

                            <param-name>contextConfigLocation</param-name>

                            <param-value>classpath:configs/spring-servlet.xml</param-value>

                   </init-param>

                   <load-on-startup>1</load-on-startup>

         </servlet>

         <!-- spring mvc 请求后缀 -->

         <servlet-mapping>

                   <servlet-name>Dispatcher</servlet-name>

                   <url-pattern>/</url-pattern>

         </servlet-mapping>

         <welcome-file-list>

                   <welcome-file>index.jsp</welcome-file>

         </welcome-file-list>

</web-app>

  

Pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.sk</groupId>
  <artifactId>springweb_mvn</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>springweb_mvn Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <properties>
  	  <spring.version>4.1.4.RELEASE</spring.version>
  </properties>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
	    <groupId>org.springframework</groupId>
	    <artifactId>spring-webmvc</artifactId>
	    <version>${spring.version}</version>
    </dependency>
    
  </dependencies>
  <build>
    <finalName>springweb_mvn</finalName>
  </build>
</project>

  

Spring最简设置

标签:

原文地址:http://www.cnblogs.com/iaoc/p/5153873.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!