1:Maven引入相关的jar包。

<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.shyroke</groupId>
<artifactId>mySpringMvc</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>mySpringMvc Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.2.3.RELEASE</version>
</dependency> <dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.2.3.RELEASE</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>4.2.3.RELEASE</version>
</dependency> <dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency> <dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.1.2</version>
</dependency> </dependencies>
<build>
<finalName>mySpringMvc</finalName>
</build>
</project>

2:web.xml配置

<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app> <!-- 配置Spring环境 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring.xml</param-value>
</context-param> <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- end -->
<!-- 配置Spring内存监听器 -->
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>
<!-- end --> <!-- 配置SpringMvc,注意springmvc的启动级别 -->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet> <servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- end --> <welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>

3: 配置springmvc-servlet.xml

<?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.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd"> <!-- 激活@Required @Autowired @Resource等标注 -->
<context:annotation-config></context:annotation-config> <!-- DispatcherServlet上下文,扫描base-package包中的类,并自动加载到spring容器中 -->
<context:component-scan base-package="com.shyroke.controller">
</context:component-scan> <!-- 启用@Component,@Controller,@Service,@Repository注解驱动 -->
<mvc:annotation-driven></mvc:annotation-driven> <!-- 配置视图解析器 -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/views/" />
<property name="suffix" value=".jsp" />
</bean> </beans>

4:配置spring.xml

<?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" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd"> <context:annotation-config></context:annotation-config>
<context:component-scan base-package="com.shyroke.service">
<!-- context:exclude-filter标签用于去除某个注解,使之不生效,因为spring中不需要controller springmvc才需要-->
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
<context:exclude-filter type="annotation"
expression="org.springframework.web.bind.annotation.ControllerAdvice" />
</context:component-scan> <bean name="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url"
value="jdbc:mysql://localhost:3306/test?useUnicode=true&amp;characterEncoding=UTF-8"></property>
<property name="username" value="root"></property>
<property name="password" value=""></property>
</bean> <!-- <bean name="sessionFactory"></bean> --> <!-- 事务 -->
<bean name="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"
proxy-target-class="true" /> </beans>
  • 到这里配置就差不多完成了,接下来写Controler、写Service/Dao、将Service对象注入到Controll等开发步骤。
  • 案例代码在here

(十一)springmvc和spring的整合的更多相关文章

  1. springMVC+MyBatis+Spring+maven 整合(1)

    1.首先第一步.部署mybatis ; 1.1 下载myBatis MyBits前身是iBitis,相对于Hibernate而言,它是半自动化ORM框架.由于老板对性能要求的比较苛刻,不得不放弃我亲爱 ...

  2. idea spring+springmvc+mybatis环境配置整合详解

    idea spring+springmvc+mybatis环境配置整合详解 1.配置整合前所需准备的环境: 1.1:jdk1.8 1.2:idea2017.1.5 1.3:Maven 3.5.2 2. ...

  3. 3.springMVC+spring+Mybatis整合Demo(单表的增删该查,这里主要是贴代码,不多解释了)

    前面给大家讲了整合的思路和整合的过程,在这里就不在提了,直接把springMVC+spring+Mybatis整合的实例代码(单表的增删改查)贴给大家: 首先是目录结构: 仔细看看这个目录结构:我不详 ...

  4. 2.springMVC+spring+Mybatis整合

    前面已经说了,springMVC+spring+Mybatis的整合思路了,现在就照着这个思路来做一下: 在开始之前先来看一下工程的目录结构: config这个目录底下放的都是配置文件: mybati ...

  5. springMVC+MyBatis+Spring 整合(2)

    mybatis 与Spring 的整合. 1.导入Spring 和Springmvc的包 pom <project xmlns="http://maven.apache.org/POM ...

  6. 菜鸟级springmvc+spring+mybatis整合开发用户登录功能(上)

    由于本人愚钝,整合ssm框架真是费劲了全身的力气,所以打算写下这篇文章,一来是对整个过程进行一个回顾,二来是方便有像我一样的笨鸟看过这篇文章后对其有所帮助,如果本文中有不对的地方,也请大神们指教. 一 ...

  7. 菜鸟级springmvc+spring+mybatis整合开发用户登录功能(下)

    昨天介绍了mybatis与spring的整合,今天我们完成剩下的springmvc的整合工作. 要整合springmvc首先得在web.xml中配置springmvc的前端控制器DispatcherS ...

  8. Spring+SpringMVC+MyBatis深入学习及搭建(十一)——SpringMVC架构

    转载请注明出处:http://www.cnblogs.com/Joanna-Yan/p/6985816.html 前面讲到:Spring+SpringMVC+MyBatis深入学习及搭建(十)--My ...

  9. springMVC+Hibernate4+Spring整合一(配置文件部分)

    本实例采用springMvc hibernate 与 spring 进行整合, 用springmvc 取代了原先ssh(struts,spring,hibernate)中的struts来扮演view层 ...

随机推荐

  1. qt 添加程序插件目录

    QApplication::addLibraryPath(QApplication::applicationDirPath()); QApplication::addLibraryPath(QAppl ...

  2. 【Python】把文件名命名成canlendar.py竟然导致无法使用canlendar模块 附赠2020年月历

    这个bug困扰了我一阵,直到在 http://www.codingke.com/question/15489 找到了解决问题的钥匙,真是没想到居然是这个原因导致的. 下面是出错信息,可以看到只要目录下 ...

  3. Docs-.NET-C#-指南-语言参考-预处理器指令:#if 预处理指令

    ylbtech-Docs-.NET-C#-指南-语言参考-预处理器指令:#if 预处理指令 1.返回顶部 1. #if(C# 参考) 2018/06/30 如果 C# 编译器遇到 #if 指令,最终是 ...

  4. IntelliJ IDEA中构建spring-boot项目

    1. 打开 IDEA ,新建项目 2. 选择Spring Initializr 并在 Choose Initializr Service URL 填入 https://start.spring.io ...

  5. CYLTabBarController的简单使用

    #pragma mark- 登录成功跳转至主页 -(void)jumpToMainVC { [UIApplication sharedApplication].statusBarStyle = UIS ...

  6. 过滤emoji表情的方法

    public static function replaceEmoji($str) { $str = preg_replace_callback( '/./u', function (array $m ...

  7. python多进程实例详解

    写在前面:python中的多线程其实并不是真正的多线程,如果想要充分地使用多核CPU的资源,在python中大部分情况需要使用多进程.Python提供了非常好用的多进程包multiprocessing ...

  8. 单点登录系统(SSO)详细设计说明书(上篇)

    1.引言 1.1编写目的 为了单点登录系统(SSO系统)的可行性,完整性,并能按照预期的设想实现该系统,特编写需求说明书.         同时,说明书也发挥与策划和设计人员更好地沟通的作用. 1.2 ...

  9. some code about numpy and notes about copy&broadcasting

    import numpy as np np.__version__ #版本 #由于python的list不要求存储同样的类型,但是效率不高. L = [i for i in range(10)] L[ ...

  10. python 优雅的解析 jsonp

    一段 jsonp 格式数据 mtopjsonpweexcb1({"api":"mtop.taobao.idle.recycle.nextspunav.get", ...