spring junit--基础配置
来源:互联网 发布:刚哥哥淘宝店招制作 编辑:程序博客网 时间:2024/05/01 14:54
spring官方文档总提示要进行SpringJunit测试必须先配置两个信息:
1、使用Spring IOC功能配置
2、配置正确的JDBC或ORM框架连接数据库
下面进行spring3和hibernate4测试平台基础配置说明:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd">
<context:annotation-config />
<context:component-scan base-package="com.cml.*">
</context:component-scan>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/jpa" />
<property name="user" value="root" />
<property name="password" value="root" />
<property name="minPoolSize" value="3" />
<property name="maxPoolSize" value="30" />
<property name="initialPoolSize" value="3" />
<property name="maxIdleTime" value="25000" />
<property name="acquireIncrement" value="1" />
<property name="acquireRetryAttempts" value="30" />
<property name="acquireRetryDelay" value="1000" />
<property name="testConnectionOnCheckin" value="true" />
<property name="idleConnectionTestPeriod" value="18000" />
<property name="checkoutTimeout" value="3000" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:/hibernate.cfg.xml">
</property>
<property name="dataSource" ref="dataSource" />
</bean>
<bean name="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
</beans>
1、注意如果你使用的是hibernate3则需要将org.springframework.orm.hibernate4.HibernateTransactionManage改为org.springframework.orm.hibernate3.HibernateTransactionManage
2、此处使用出c3p0连接池,可以根据实际情况更改
3、hibernate配置文件为:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
</session-factory>
</hibernate-configuration>
需要制定数据库方言
- spring junit--基础配置
- spring junit 配置
- Spring boot配置Junit
- Spring中配置Junit
- Spring基础之Junit测试
- JUnit 中加载spring 配置
- junit继承spring配置信息
- Spring入门1---Spring+junit配置
- [Spring]简单Junit和Spring整合配置
- spring单元测试junit及spring配置
- Spring整合Junit测试,并且配置事务
- JUNIT -- 调用spring配置进行测试
- 通过JUnit启动spring加载配置
- Java Spring搭配Junit测试配置
- Android基础学习:Junit测试基本配置
- spring配置redis的单元测试(spring-test,junit)
- jUnit Spring
- Junit+Spring
- centos CentOS-6.2-i386-minimal 安装gnome桌面环境
- 深入理解Hadoop集群和网络
- 二路归并排序
- 每日一编c-7
- Content Providers(内容提供器)
- spring junit--基础配置
- Cracking The Coding Interview 4.2_暂存
- Linux设备模型(6)_Bus
- iOS study Day19 - 滑动方向判断
- Hibernate4.3 buildSessionFactory过时解决方案
- onTouchListener和onClickListener的冲突问题
- 希尔排序
- 很多时候我们只是找到了人,而不是找到了自己喜欢的人
- 在.Net C#中使用分布式缓存系统Memcached