一.使用myeclipse 创建一个新的 maven项目.

  (ps:1.在filter过滤的时候输入 webapp 选择"maven-archetype-webapp". 2.在main下建一个java文件夹(建source folder可能不能成功))

  具体可参考:http://www.cnblogs.com/waniu/p/3798775.html

二.将project 转变成webproject.(右键--properties--myeclipse--project facets-->勾选"dynamic web module")(如果已经是web 可省去此操作.)

三.为project赋予spring mvc的特性.

  在WEB-INF目录下建立:applicationContext.xml,**-servlet.xml并且配置web.xml三个文件.分别为

  web.xml

web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  <!--listener里边配置的是,表示项目启动时候会去读取applicationContext.xml,去实例化bean-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <servlet>
<servlet-name>exam</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet> <servlet-mapping>
<servlet-name>exam</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping> <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

  启动时会默认在/WEB-INF目录下查找applicationContext.xml作为spring容器的配置文件,这里可以初始化一些bean,如DataSource。我们这里什么也不做。代码如下:applicationContext.xml(暂时不配置具体bean)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
</beans>

启动时也会默认在/WEB-INF目录下查找XXX-servlet.xml作为配置文件,XXX就是DispatcherServlet的名字,该文件中将配置两项重要的mvc特性:

HandlerMapping,负责为DispatcherServlet这个前端控制器的请求查找Controller;

ViewResolver,负责为DispatcherServlet查找ModelAndView的视图解析器。

<?xml version="1.0" encoding="UTF-8"?>
<!-- Bean头部 -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd"> <!-- 激活@Controller模式 -->
<mvc:annotation-driven />
<!-- 对包中的所有类进行扫描,以完成Bean创建和自动依赖注入的功能 需要更改 -->
<context:component-scan base-package="cc.monggo.web.controller" /> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>

四: 配置pom.xml,让maven解决jar包依赖问题

pom.xml:

pop.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>exam</groupId>
<artifactId>exam_3</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>exam_3 Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.0.5.RELEASE</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.0.5.RELEASE</version>
</dependency> <dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_2.5_spec</artifactId>
<version>1.2</version>
</dependency> </dependencies>
<build>
<finalName>exam_3</finalName>
</build>
</project>

这样一个最基本spring mvc项目就配置好了

此时对于实现部署测试过的项目启动时候可能会引发:

严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener

重新部署服务器,试试应该就可以了.

五: 打包部署:

  maven项目打包很容易,直接右键项目 run as --maven install 就会在 target目录下构建 ***.war 部署包,将部署包放入到应用服务器下,即可完成部署运行.

参考文章:

http://www.cnblogs.com/fangjins/archive/2012/05/06/2485459.html

http://blog.csdn.net/sapphire_aling/article/details/6947108

最新文章

  1. ubuntu安装navicat及常见问题解决
  2. IOS 开发中 Whose view is not in the window hierarchy 错误的解决办法
  3. (转)Genymotion安装virtual device的“unable to create virtual device, Server returned Http status code 0”的解决方法
  4. TabLayout学习笔记
  5. 关于MATLAB处理大数据坐标文件2017620
  6. Go语言学习笔记(五)文件操作
  7. TFboy养成记 tensorboard
  8. 我的java学习之路--Java注解专题
  9. 套接字编程相关函数(1:套接字地址结构、字节序转换、IP地址转换)
  10. Python + Appium 环境搭建
  11. Python3的List操作和方法
  12. Python_记一次网站数据定向爬取实现
  13. endnote格式
  14. ADO读写DateTime方式
  15. dubbo配置多个注册中心
  16. 发布npm
  17. 移动端页面利用好viewport,适配各种宽度屏幕
  18. php图片转base64
  19. 一个封存Id与状态对应键值的神器,BigInteger的setBit和testBit用法实例
  20. (3.4)mysql基础深入——mysql.server启动脚本源码阅读与分析

热门文章

  1. font awesome的图标在WP8浏览器下无法显示的问题解决
  2. Chapter Querying Data
  3. MemoryStream 的GetBuffer() 和 ToArray()的区别
  4. Objective-C的内存管理
  5. Openstack-Mitaka Ceilometer 中使用 SNMP 监控真实物理机
  6. X86 架构和 ARM 架构
  7. 既约分数-phi
  8. ZJOI2009 假期的宿舍
  9. ubuntu13.10无有线网卡驱动
  10. [设计模式 3] 用设计模式的眼光看MVC框架