集成SpringMVC, Spring, Mybatis环境
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param> <!-- ContextLoadListener常用于加载Spring的配置 --> <listener>
<listener-class>org.springframework.web.servlet.DispatcherServlet</listener-class>
</listener> <!-- 配置DispatchcerServlet -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param> <!-- 而DispatcherSerclet用来加载SpringMVC的配置 -->
<param-name>contextConfigLocation</param-name>
<param-value>classpath:dispatcher-servlet.xml</param-value>
</init-param>
<!-- 配置初始化优先级 -->
<load-on-startup>2</load-on-startup>
</servlet> <servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
SpringMVC的配置(dispatcher-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:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
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-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"> <!-- 使用注解驱动 -->
<mvc:annotation-driven /> <!-- 定义扫描装载的包 -->
<context:component-scan base-package="Controller" /> <!-- 视图解析器 -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/" p:suffix=".jsp"/> <!-- 配置开启注解事务 -->
<tx:annotation-driven transaction-manager="transactionManager" />
</beans>
Spring的配置(appilicationContext.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:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
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-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
<!-- 注解驱动 -->
<context:annotation-config/> <!-- 数据库连接池 -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
<property name="username" value="root"></property>
<property name="password" value=""></property>
<property name="driverClass" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/housekeeping"></property>
</bean> <!-- 集成mybatis -->
<bean id="SqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="configLocation" value="classpath:mybatis-config.xml"></property>
</bean> <bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="Mapper" />
<property name="SqlSessionFactoryBeanName" value="SqlSessionFactory" /> <!-- 指定加了注解才视之为Mapper -->
<property name="annotationClass" value="org.springframework.stereotype.Repository" />
</bean> </beans>
集成SpringMVC, Spring, Mybatis环境的更多相关文章
- Maven构建 SpringMVC+Spring+MyBatis 环境整合
目录 1. Maven 项目搭建 2. Maven 插件生成 MyBatis 代码 3. 待续 ... 开发环境 开发环境请尽量保持一致,不一致的情况可能存在问题. JDK 1.7 MyEclipse ...
- spring+websocket综合(springMVC+spring+MyBatis这是SSM框架和websocket集成技术)
java-websocket该建筑是easy.儿童无用的框架可以在这里下载主线和个人教学好java-websocket计划: Apach Tomcat 8.0.3+MyEclipse+maven+JD ...
- Idea SpringMVC+Spring+MyBatis+Maven调整【转】
Idea SpringMVC+Spring+MyBatis+Maven整合 创建项目 File-New Project 选中左侧的Maven,选中右侧上方的Create from archetyp ...
- SpringMVC+Spring+MyBatis+Maven调整【转】
Idea SpringMVC+Spring+MyBatis+Maven整合 创建项目 File-New Project 选中左侧的Maven,选中右侧上方的Create from archetyp ...
- springMVC,spring,mybatis全注解搭建框架--第一步,让框架跑起来
自己从事java开发工作也有一年多了,自己却没有亲手搭建一个完整的框架.于是今天自己动手搭建一个,过程中遇到一些问题,倒腾了大半天终于搞定了. 现在给大家分享一下过程,自己也记录下来,以后学习参考使用 ...
- springmvc学习总结(二) -- maven+springmvc+spring+mybatis+mysql详细搭建整合过程讲解
@_@ 写在最前 之前分享过下面这几篇: mybatis学习笔记(五) -- maven+spring+mybatis从零开始搭建整合详细过程(上)(附demo和搭建过程遇到的问题解决方法) myba ...
- 手把手教你整合 SpringMvc+Spring+MyBatis+Maven
注:该教程是参考孙宇老师的<SpringMvc+Spring+Mybatis+Maven整合视频教程1>整理的,花了我六个多小时,边复习视频边调代码边写教程,保证该教程每一步都能正确执行, ...
- mybatis学习(十一)——springmvc++spring+mybatis整合
做任何一个项目都以一个需求,这里先定义一下需求:利用三大框架查询酒店列表. 一.搭建开发环境 1.创建一个web项目 我这里用的是 jdk1.8+tomact7.0 2.创建hotel表 CREATE ...
- maven+springmvc+spring+mybatis+mysql详细搭建整合过程讲解
转自:https://www.cnblogs.com/lmei/p/7190755.html?utm_source=itdadao&utm_medium=referral @_@ 写在最前 之 ...
随机推荐
- 【EOJ Monthly 2018.2 (Good bye 2017)】
23333333333333333 由于情人节要回家,所以就先只放代码了. 此题是与我胖虎过不去. [E. 出老千的 xjj] #include<cstdio> #include<c ...
- 「SDFZ听课笔记」二分图&&网络流
二分图? 不存在奇环(长度为奇数的环)的图 节点能黑白染色,使得不存在同色图相连的图 这两个定义是等价哒. 直观而言,就是这样的图: 二分图有一些神奇的性质,让一些在一般图上复杂度飞天的问题可以在正常 ...
- bootstrap table 根据单元格中的数据改变单元格的样式
在bootstrap-table.js里面列属性 formatter就是用来格式化单元格的,其默认值是undefined 类型是function,function(value, row, index ...
- JAVA THINGKING (一)
保存数据位置: (1) 寄存器.这是最快的保存区域,因为它位于和其他所有保存方式不同的地方:处理器内部. (2) 堆栈.驻留于常规RAM(随机访问存储器)区域,这是一种特别快.特别有效的数据保存方式, ...
- GMap.NET 显示GIF图标的定制
利用System.Drawing.ImageAnimator类实现GIF图标显示 public class GMapMarkerImage : GMapMarker { private Image i ...
- pytest用例setup和teardown
函数式以下两种: setup_function/teardown_function 每个用例开始和结束调用一次 setup_module/teardown_module setup_modu ...
- 你忘记的java的数据类型信息
java有8种基本数据类型 int long short byte float double char boolean: 三种情况造成数据溢出 无穷大,无穷小, NAN: 常量 声明为final的变量 ...
- StackOverFlow页面不正常,因为CDN被墙了
190.93.247.58 cdn.sstatic.net 198.252.206.140 sstatic.net http://stackoverflow.com/
- Beyond Compare 简体版+注册码
Beyond Compare 3.3.4.14431 官方简体版+注册码 查阅全文 ›
- Docker管理应用数据
1. Manage data in Docker 默认情况下,所有在容器内部创建的文件被存储在一个可写的容器层.这就意味着: 当容器不存在的时候,数据不能被持久化,而且在容器外部想要读取这些数据十分 ...