Spring的基于ApsectJ的注解的AOP开发
1.创建项目,引入jar包
2.引入配置文件
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
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.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- 在配置文件中开启注解的AOP的开发======== -->
<aop:aspectj-autoproxy />
<bean id="orderDao" class="com.wangshi.spring.demo01.OrderDao"/>
<!-- 配置切面类 -->
<bean id="myAspext" class="com.wangshi.spring.demo01.MyAspectAnno"/>
</beans>
3.编写目标类并配置
package com.wangshi.spring.demo01;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
/**
* @author wanghaichuan
* 创建目标类
*
*/
public class OrderDao {
public void save(){
System.out.println("这是Order的保存........");
}
public void update(){
System.out.println("这是update的更新........");
}
public String delete(){
System.out.println("这是delete的删除........");
return "王者";
}
public void find(){
System.out.println("这是find的查询........");
//int i=1/0;
}
}
4.编写切面类并配置,请看下面代码
5.使用注解的AOP对象目标类进行增强
6.编写测试类
package com.wangshi.spring.demo01;
import javax.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* spring 的单元测试 AspectJ注解
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext01.xml")
public class SpringDemo {
@Resource(name="orderDao")
private OrderDao orderDao;
@Test
public void demo(){
orderDao.save();
orderDao.update();
orderDao.delete();
orderDao.find();
}
}
7.Spring的注解的AOP的通知类型
@before : 前置通知
@AfterReturning :后置通知
@Around :环绕通知
@AfterThrowing :异常抛出通知
@After :最终通知
package com.wangshi.spring.demo01;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
/**
* @author wanghaichuan
*编写切面类并配置
*/
@Aspect
public class MyAspectAnno {
/**
* 前置通知
*/
@Before(value="execution(* com.wangshi.spring.demo01.OrderDao.save(..))")
public void before(){
System.out.println("前置增强==========");
}
/**
* 后置通知
*/
@AfterReturning(value="execution(* com.wangshi.spring.demo01.OrderDao.delete(..))",returning="result")
public void afterReturning(Object result){
System.out.println("后置增强=========="+result);
}
/**
* 环绕增强
* @return
* @throws Throwable
*/
@Around(value="execution(* com.wangshi.spring.demo01.OrderDao.update(..))")
public Object around(ProceedingJoinPoint joinPoint) throws Throwable{
System.out.println("环绕之前========");
Object obj = joinPoint.proceed();
System.out.println("环绕之后========");
return obj;
}
/**
* 异常抛出通知
* @return
* @throws Throwable
*/
@AfterThrowing(value="execution(* com.wangshi.spring.demo01.OrderDao.find(..))",throwing="ex")
public void afterThrowing(Throwable ex){
System.out.println("异常抛出通知==="+ex);
}
/**
* 最终通知
* @return
* @throws Throwable
*/
@After(value="execution(* com.wangshi.spring.demo01.OrderDao.find(..))")
public void after(){
System.out.println("最终通知增强====");
}
}
Spring的注解的AOP的切入点的配置
Spring的JDBC的模板的使用
1.Spring的JDBC的模板
Spring是EE开发的一站式的框架,有EE开发的每层的解决方案。Spring对持久层也提供了解决方案:ORM模块和JDBC的模板。
Spring提供了很多的模板用于简化开发:
2.JDBC模板使用的入门
-
创建项目,引入jar包
引入基本开发包 数据库驱动 Spring的JDBC模板的jar包
- 创建数据库和表
create database spring4;
use spring4;
create table account(
id int primary key auto_increment,
name varchar(20),
money double
);
- 使用JDBC的模板:保存数据
package com.wangshi.springjdbc.demo;
import org.junit.Test;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
/**
* @author wanghaichuan
*spring中使用JDBC的模板
*/
public class JDBCDemo {
@Test
//jdbc模板的使用类似于DButils;
public void demo01(){
//创建连接池(springJDBC内置连接)
DriverManagerDataSource datasource = new DriverManagerDataSource();
datasource.setDriverClassName("com.mysql.jdbc.Driver");
datasource.setUrl("jdbc:mysql:///spring4");
datasource.setUsername("root");
datasource.setPassword("root");
//创建jdbc模板
JdbcTemplate JdbcTemplate = new JdbcTemplate(datasource);
JdbcTemplate.update("insert into account values(null,?,?)","外框",1000d);
}
}
3.将连接池和模板交给Spring管理
- 引入Spring的配置文件,引入spring_aop的jar包
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
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.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- 引入spring的配置文件 ============-->
<!-- 配置Spring的内置的连接,spring默认是单例的 -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<!-- 注入属性 -->
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql:///spring4"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
</bean>
<!-- 配置spring的JDBC的模板========= -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"/>
</bean>
</beans>
- 使用Jdbc的模板
package com.wangshi.springjdbc.demo;
import javax.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author wanghaichaun
*使用spring的JDBC模板,注解方式;
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
public class JDBCDemo01 {
@Resource(name="jdbcTemplate")
private JdbcTemplate jdbcTemplate;
@Test
public void Demo(){
jdbcTemplate.update("insert into account values(null,?,?)","洒出",12232d);
}
}
使用开源的数据库连接池:
DBCP的使用:
1.引入jar包
2.配置DBCP连接池
<!-- 配置dbcp连接池============ -->
<bean id="dataSource" class=" org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql:///spring4"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
</bean>
<!-- 配置spring的DBCP的模板 -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"/>
</bean>
3.模板都是一样的
C3P0的使用
- 引入c3p0连接池jar包
- 配置c3p0连接池(具体数据)
<!-- 配置c3p0的连接池(具体数据) -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="com.mysql.jdbc.Driver"/>
<property name="jdbcUrl" value="jdbc:mysql:///spring04"/>
<property name="user" value="root"/>
<property name="password" value="root"/>
</bean>
<!-- 配置spring的模板 -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"/>
</bean>
但是在实际开发项目中,我们经常用配置文件jdbc.properties;
抽取配置到属性文件
- 定义一个属性文件jdbc.properties
jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql:///spring04
jdbc.username=root
jdbc.password=root
- 在Spring的配置文件中引入属性文件[两种方式]
- 第一种:
<!-- 第一种方式:通过bean标签引入的 -->
<bean class=" org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:jdbc.properties"/>
</bean>
- 第二种:
<!-- 第二种方式,通过context标签引入的 -->
<context:property-placeholder location="classpath:jdbc.properties"/>
- 引入属性文件的值
<!-- 引入属性的值,配置c3p0; -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driverClass}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
- 测试
使用JDBC的模板完成CRUD的操作
package com.wangshi.springjdbc.demo;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import javax.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.wangshi.springjdbc.entity.Account;
/**
* @author wanghaichaun
*使用spring的模板,注解方式;增删改查
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
public class JDBCDemo01 {
@Resource(name="jdbcTemplate")
private JdbcTemplate jdbcTemplate;
@Test
//保存操作
public void Demo(){
jdbcTemplate.update("insert into account values(null,?,?)","你看嘛",12565d);
}
@Test
//修改操作
public void demo02(){
jdbcTemplate.update("update account set name=?,money=? where id=?","语言",1500d,3);
}
@Test
//删除操作
public void demo03(){
jdbcTemplate.update("delete from account where id=?",2);
}
@Test
//查询操作 查询某个操作
public void demo04(){
String name = jdbcTemplate.queryForObject("select name from account where id =?" ,String.class,3);
System.out.println(name);
}
@Test
//查询操作 统计查询
public void demo05(){
Long count = jdbcTemplate.queryForObject("select count(*) from account ",Long.class);
System.out.println(count);
}
@Test
//查询返回对象或集合 [封装到一个对象中]
public void demo06(){
Account account = jdbcTemplate.queryForObject("select * from account where id=?", new MyRowMapper(),3);
System.out.println(account);
}
@Test
//查询多条记录
public void demo07(){
List<Account> list = jdbcTemplate.query("select * from account",new MyRowMapper() );
for (Account account : list) {
System.out.println(account);
}
}
//数据封装
class MyRowMapper implements RowMapper<Account>{
public Account mapRow(ResultSet rs, int rowNum) throws SQLException {
Account account = new Account();
account.setId(rs.getInt("id"));
account.setName(rs.getString("name"));
account.setMoney(rs.getDouble("money"));
return account;
}
}
}
Spring的事务管理
-
Spring的事务管理的API
1.PlatformTransactionManager:平台事务管理器
平台事务管理器:接口,是Spring用于管理事务的真正的对象。DataSourceTransactionManager :底层使用JDBC管理事务 HibernateTransactionManager :底层使用Hibernate管理事务
-
TransactionDefinition :事务定义信息
事务定义:用于定义事务的相关的信息,隔离级别、超时信息、传播行为、是否只读; -
TransactionStatus:事务的状态
事务状态:用于记录在事务管理过程中,事务的状态的对象。 -
事务管理的API的关系:
Spring进行事务管理的时候,首先平台事务管理器根据事务定义信息进行事务的管理,在事务管理过程中,产生各种状态,将这些状态的信息记录到事务状态的对象中。
Spring的事务的传播行为
Spring中提供了七种事务的传播行为:
-
保证多个操作在同一个事务中:
PROPAGATION_REQUIRED :默认值,如果A中有事务,使用A中的事务,如果A没有,创建一个新的事务,将操作包含进来 PROPAGATION_SUPPORTS :支持事务,如果A中有事务,使用A中的事务。如果A没有事务,不使用事务。 PROPAGATION_MANDATORY :如果A中有事务,使用A中的事务。如果A没有事务,抛出异常。
-
保证多个操作不在同一个事务中
PROPAGATION_REQUIRES_NEW :如果A中有事务,将A的事务挂起(暂停),创建新事务,只包含自身操作。如果A中没有事务,创建一个新事务,包含自身操作。 PROPAGATION_NOT_SUPPORTED :如果A中有事务,将A的事务挂起。不使用事务管理。 PROPAGATION_NEVER :如果A中有事务,报异常。
-
嵌套式事务
PROPAGATION_NESTED :嵌套事务,如果A中有事务,按照A的事务执行,执行完成后,设置一个保存点,执行B中的操作,如果没有异常,执行通过,如果有异常,可以选择回滚到最初始位置,也可以回滚到保存点。
搭建Spring的事务管理的环境
转账环境的搭建
1.创建Service的接口和实现类
package com.wangshi.springjdbc.tx;
/*转账的业务层的接口
* @author wanghaichaun
*转出人 转入人 转了多少钱
*/
public interface AccountService {
public void transfer(final String from,final String to,final Double money);
}
实现类:
package com.wangshi.springjdbc.tx;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
import org.springframework.transaction.support.TransactionTemplate;
/**业务层的实现类
* @author wanghaichuan
*
*/
public class AccountServiceImpl implements AccountService{
//注入dao层
private AccountDao accountDao;
public void setAccountDao(AccountDao accountDao) {
this.accountDao = accountDao;
}
/**
*from:转出的账号
*to: 转入的账号
*money:转账金额
*/
@Override
public void transfer(final String from,final String to,final Double money) {
accountDao.outMoney(from, money);
accountDao.inMoney(to, money);
}
}
2.创建DAO的接口和实现类
在DAO中编写扣钱和加钱方法:
package com.wangshi.springjdbc.tx;
/**
* @author wanghaichaun
*转账的dao接口
*扣钱 加钱
*/
public interface AccountDao {
public void outMoney(String from,Double money);
public void inMoney(String to,Double money);
}
package com.wangshi.springjdbc.tx;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
/**
* @author wanghaichuan
*创建dao层的实现类
*/
public class AccountDaoImpl extends JdbcDaoSupport implements AccountDao {
@Override
public void outMoney(String from, Double money) {
this.getJdbcTemplate().update("update account set money = money - ? where name = ?", money,from);
}
@Override
public void inMoney(String to, Double money) {
this.getJdbcTemplate().update("update account set money = money + ? where name = ?", money ,to);
}
}
3.配置Service和DAO:交给Spring管理
配置连接池和JDBC的模板并在DAO注入Jdbc的模板:
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
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.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- 引入spring的配置文件 ============-->
<!-- 配置service和dao层,交给spring管理 -->
<bean id="accountService" class="com.wangshi.springjdbc.tx.AccountServiceImpl">
<property name="accountDao" ref="accountDao"/>
<!-- 注入 事务管理的模板 -->
<!-- <property name="trsactionTemplate" ref="transactionTemplate"/> -->
</bean>
<bean id="accountDao" class="com.wangshi.springjdbc.tx.AccountDaoImpl">
<!-- 在dao层注入jdbc模板 -->
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 配置连接池和jdbc模板 -->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- c3p0连接池 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driverClass}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<!-- 配置平台事务管理器============================= -->
<!-- <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean> -->
<!-- 配置事务管理的模板 -->
<!-- <bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate">
<property name="transactionManager" ref="transactionManager"/>
</bean> -->
</beans>
4.测试
package com.wangshi.springjdbc.tx;
import javax.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author wanghaichuan
*测试转账环境
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:tx.xml")
public class SpringDemo {
@Resource(name="accountService")
public AccountService accountService;
@Test
public void demo(){
accountService.transfer("兰书记", "你看嘛", 500d);
}
}
Spring的事务管理:
一是:编程式事务(需要手动编写代码)–了解
第一步:配置平台事务管理器
<!-- 配置平台事务管理器============================= -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
第二步:Spring提供了事务管理的模板类
<!-- 配置事务管理的模板 -->
<bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate">
<property name="transactionManager" ref="transactionManager"/>
</bean>
第三步:在业务层注入事务管理的模板
编写事务管理的代码:
测试:
二是 : 声明式事务管理(通过配置实现)—AOP,也有两类
1.XML方式的声明式事务管理
第一步:引入aop的开发包
第二步:恢复转账环境
第三步:配置事务管理器
第四步:配置增强
<!-- 配置增强 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<!-- 事务管理的规则 -->
<!-- <tx:method name="save*" propagation="REQUIRED" isolation="DEFAULT"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="delete" propagation="REQUIRED"/>
<tx:method name="find*" read-only="true"/> -->
<tx:method name="*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
第五步:AOP的配置
<!-- AOP的配置 -->
<aop:config>
<aop:pointcut expression="execution(* com.wangshi.springjdbc.tx02.AccountServiceImpl.*(..) )" id="pointcut1"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="pointcut1"/>
</aop:config>
测试:
2.注解方式的声明式事务管理
第一步:引入aop的开发包
第二步:恢复转账环境
第三步:配置事务管理器
第四步:开启注解事务
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
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.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- 配置Service============= -->
<bean id="accountService" class="com.wangshi.springjdbc.tx03.AccountServiceImpl">
<property name="accountDao" ref="accountDao"/>
</bean>
<!-- 配置DAO================= -->
<bean id="accountDao" class="com.wangshi.springjdbc.tx03.AccountDaoImpl">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 配置连接池和JDBC的模板 -->
<!-- 第二种方式通过context标签引入的 -->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 配置C3P0连接池=============================== -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driverClass}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" >
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 开启注解事务 -->
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
第五步:在业务层添加注解
package com.wangshi.springjdbc.tx03;
import org.springframework.transaction.annotation.Transactional;
/**
* @author wanghaichaun
*这是业务层的实现
*/
@Transactional
public class AccountServiceImpl implements AccountService{
private AccountDao accountDao;
public void setAccountDao(AccountDao accountDao) {
this.accountDao = accountDao;
}
/**
*from:转出的账号
*to: 转入的账号
*money:转账金额
*/
@Override
public void transfer(String from, String to, Double money) {
accountDao.outMoney(from, money);
int i = 1/0;
accountDao.inMoney(to, money);
}
}
测试:
package com.wangshi.springjdbc.tx03;
import javax.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author wanghaichaun
*测试
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:tx03.xml")
public class SpringDemo {
@Resource(name="accountService")
private AccountService accountService;
@Test
public void demo(){
accountService.transfer("兰书记", "你看嘛", 500d);
}
}
-----------------------------------------------------------------------------------明天会更好!