搭建maven+spring+freemaker+mybatis环境之四
来源:互联网 发布:网络电视机顶盒牌子 编辑:程序博客网 时间:2024/06/13 21:40
此篇在前面的基础上加入了mybatis
先说两个配置文件的修改,在spring-servlet.xml里加入了下面的代码,抽出了freemaker的配置
<span style="white-space:pre"></span><beanclass="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"><property name="locations" value="classpath:freemarker.properties" /></bean>
在spring.xml里加入了 下面的代码,用于存放数据库连接的属性
<context:property-placeholder location="classpath:jdbc.properties" />
jdbc.properties的内容:
<pre name="code" class="html">driver=com.mysql.jdbc.Driverurl=jdbc:mysql://121.40.120.111:3306/gnxusername=gnxMonitor1password=gnxPassword
一、pom.xml里增加数据库连接需要的包,我挨个搜了搜,尽量保证最新,并把之前spring的相关包升级到了,<version>4.2.2.RELEASE</version>
<span style="white-space:pre"></span><!-- mybatis 的jar --><dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.3.0</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>1.2.3</version> </dependency> <!-- 数据库连接dbcp --><dependency><groupId>org.apache.commons</groupId><artifactId>commons-dbcp2</artifactId><version>2.1.1</version></dependency><dependency><groupId>org.apache.commons</groupId><artifactId>commons-pool2</artifactId><version>2.4.2</version></dependency><!-- mysql的jar --><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.35</version></dependency>
二.所有的配置文件都是放在src/main/resources下面,增加了spring-mybatis.xml,并在web.xml里做了初始化
spring-mybatis.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:context="http://www.springframework.org/schema/context"xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"xmlns:aop="http://www.springframework.org/schema/aop"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/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd "><!--创建jdbc数据源 dbcp --><!-- <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> --><bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource"destroy-method="close"><property name="driverClassName" value="${driver}" /><property name="url" value="${url}" /><property name="username" value="${username}" /><property name="password" value="${password}" /><!-- data source configuration --><property name="initialSize" value="10" /><!-- initial connections --><property name="maxTotal" value="100" /><!-- MAX connections --><property name="maxIdle" value="50" /><!-- MAX idle connections --><property name="minIdle" value="20" /><!-- MIN idle connections --><property name="testWhileIdle" value="true" /><property name="testOnBorrow" value="false" /><property name="testOnReturn" value="false" /><property name="validationQuery" value="select 1" /><property name="timeBetweenEvictionRunsMillis" value="20000" /><property name="numTestsPerEvictionRun" value="100" /></bean><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><property name="dataSource" ref="dataSource" /><!-- 自动扫描entity目录 xml文件 --><property name="mapperLocations" value="classpath:com/template/persist/mapper/*.xml"></property></bean><bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"><!-- 自动扫描 mybatis的接口 --><property name="basePackage" value="com.template.persist.mapper"></property><property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property></bean><!-- 事务 --><bean id="txManager"class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource" /></bean><!-- 事务注解驱动,标注@Transactional的类和方法将具有事务性 --> <tx:annotation-driven transaction-manager="txManager" /> </beans>启动没问题
明天写测试类......先.睡觉
0 0
- 搭建maven+spring+freemaker+mybatis环境之四
- 搭建maven+spring+freemaker+mybatis环境之二
- 搭建maven+spring+freemaker+mybatis环境之三
- 搭建maven+spring+freemaker+mybatis环境之五+testng
- 搭建maven+spring+freemaker+mybatis环境之一
- Maven+Spring+SpringMVC+MyBatis搭建环境心得
- maven+spring+springMVC+mybatis环境搭建
- STS +Maven+ SpringMVC+Spring+Mybatis 搭建环境
- Idea+Maven+Spring+SpringMVC+MyBatis环境搭建
- Spring+Mybatis+SpringMVC+Maven+MySql环境搭建
- 使用maven 一步一步搭建Spring+mybatis环境
- (四)从零搭建maven+spring+mybatis项目之mybatis与事务配置
- maven+Spring+SpringMVC+mybatis+mybatis-generator 搭建SSM开发环境
- 1.Maven 搭建Struts、spring、mybatis框架-安装Maven环境
- Maven搭建Spring+Struts2+Mybatis项目(一) Maven环境
- mybatis+maven 环境搭建
- Maven+Spring+Spring MVC+MyBatis+MySQL,搭建SSM框架环境
- Maven+Spring+Spring MVC+MyBatis+MySQL,搭建SSM框架环境
- 带参数启动另外一个exe程序
- 为 Key-Value 数据库实现MVCC 事务
- springMVC教程-快速入手-深入分析
- 用gdb来调试fwrite异常产生的core
- 【2015/11/15】为了解决账号登录显示用户名和登录之后退出的问题倒腾一晚上!
- 搭建maven+spring+freemaker+mybatis环境之四
- 10 种机器学习算法的要点(附 Python 和 R 代码)
- Python_元组、字典内建方法详解
- Git常用命令
- 《并查集》hdu acm 5.1.7 c++ map的使用
- 不同场景下 MySQL 的迁移方案
- Android适配器——ArrayAdapter的各种重载
- C/C++文件输入输出操作——FILE*、fstream、windowsAPI
- SQL大数据量查询的优化