spring学习笔记

[align=center][b]在学习过程中整合了一些网上的资源并注明了出处。[/b][/align]
[size=medium][b]一、spring的IOC[/b][/size]
[quote]一 : 什么是IOC(控制反转) ?

1 : 传统写法 :

public class PersonService{
private PersonDao personDao = new PersonDao();

public void save(Person person){
personDao.save(person);
}
}


2 :定义 : PersonDao 是 应用(PersonService) 内部创建和维护的。所谓控制反转就是应用(PersonService)本身不负责依赖对象(PersonDao)的创建及维护。依赖对象 (PersonDao)的创建及维护是由外部容器负责的。这样控制权就由应用转移到外部容器,控制权的转移就是所谓的反转。


二 : Spring 对事务的管理

如果想让2个业务方法在同一个事务中执行 , 前提就是这2个业务方法 必须使用同一个 Connection实例 。


判断2个实例的引用地址是否相同 只要

p1==p2 返回true 即可证明。


三 : 注解

<?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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">

<context:annotation-config/>
<context:component-scan base-package="demo1"/>
</beans>

如果想使用注解必须引入 :

命名空间 :
xmlns:context="http://www.springframework.org/schema/context"


和命名空间的 Schema :

           http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">

[i]文章来源:[/i][url]http://www.blogjava.net/liuwentao253/archive/2009/03/24/261766.html[/url]
[/quote]
用spring之后的写法
@Component
public class PersonService{
private PersonDao personDao;

public void save(Person person){

personDao.save(person);

}
public PersonDao getPersonDao() {
return personDao;
}
@Resource
public void setPersonDao(PersonDao personDao) {
this.personDao = personDao;
}
}
[i][b]备注:不错的学习资料[/b][/i]
豆丁网[url]http://www.docin.com/p-67624716.html[/url]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值