标签:
一、Spring是什么
public class PersonServiceBean { private PersonDao personDao = new PersonDaoBean(); public void save(Person person){ personDao.save(person); } }
public class PersonServiceBean { private PersonDao personDao ; //通过构造器参数,让容器把创建好的依赖对象注入进PersonServiceBean,当然也可以使用setter方法进行注入。 public PersonServiceBean(PersonDao personDao){ this.personDao=personDao; } public void save(Person person){ personDao.save(person); } }
public void payment(){ Bean1.update();//更新金额 Bean2.save();//记录操作日志 }
public class Bean1 { public void update(){//注意:下面省略了一些代码 Connection conn = null; conn.setAutoCommit(false); Statement.executeUpdate(“update account set amount=? where id=?"); } } public class Bean2 { public void save(){//注意:下面省略了一些代码 Connection conn = null; conn.setAutoCommit(false); Statement.executeUpdate(“insert into Log (content) values (?)"); } }
@Transactional(propagation=Propagation.Required) public void payment(){ Bean1.update();//更新金额 Bean2.save();//记录日志 } public class Bean1 { @Transactional(propagation=Propagation.Required) public void update(){ executeUpdate(“update account set amount=? where id=?"); } } public class Bean2 { @Transactional(propagation=Propagation.RequiresNew) public void save(){ executeUpdate(“insert into Log (content) values (?)"); } }
轻量级与重量级概念的划分
标签:
原文地址:http://www.cnblogs.com/xiaoduc-org/p/5454326.html