Spring学习笔记(一)----Spring IOC配置与应用

1.     FAQ:不给提示:

a)     window –preferences – myeclipse – xml – xml catalog

b)     UserSpecified Entries – add

                i.         Location:       D:\share\0900_Spring\soft\spring-framework-2.5.6\dist\resources\spring-beans-2.5.xsd

               ii.         URI:             file:///D:/share/0900_Spring/soft/spring-framework-2.5.6/dist/resources/spring-beans-2.5.xsd

              iii.         Key Type:      SchemaLocation

             iv.         Key:              http://www.springframework.org/schema/beans/spring-beans-2.5.xsd

2.     注入类型(参考Spring_0300_IOC_Injection_Type)

a)     setter(重要)

<property name="userDAO" ref="u" />

b)     构造方法(可以忘记)

设置构造方法

     <constructor-arg>

        <ref bean="u"/>

     </constructor-arg>

c)    接口注入(可以忘记)

3.     id vs. name(参考Spring_0400_IOC_Id_Name)

a)     name可以用特殊字符

4.     简单属性的注入(参考Spring_0500_IOC_SimpleProperty)

a)     <propertyname=… value=….>

5.     <bean>中的scope属性(参考Spring_0600_IOC_Bean_Scope)

a)     singleton 单例

b)     proptotype 每次创建新的对象

6.     集合注入(参考Spring_0700_IOC_Collections)

a)     很少用,不重要!参考程序

7.     自动装配(参考Spring_0800_IOC_AutoWire)

a)     byName

b)     byType

c)     如果所有的bean都用同一种,可以使用beans的属性:default-autowire

8.     生命周期(参考Spring_0900_IOC_Life_Cycle)

a)     lazy-init (不重要)

b)     init-methoddestroy-methd 不要和prototype一起用(了解)

9.     Annotation第一步:

a)     修改xml文件,参考文档<context:annotation-config /> xmlns:context="http://www.springframework.org/schema/context”

将其复制到<beans>标签中,并在xsi:schemaLocation中添加http://www.springframework.org/schema/context          http://www.springframework.org/schema/context/spring-context-2.5.xsd

10.  @Autowired

a)     默认按类型by type

b)     如果想用byName,使用@Qulifier

c)     写在privatefield(第三种注入形式)(不建议,破坏封装)

d)     如果写在set上,@qualifier需要写在参数上

11.  @Resource(重要)

a)     加入:j2ee/common-annotations.jar

b)     默认按名称,名称找不到,按类型

c)     可以指定特定名称

d)     推荐使用

e)     不足:如果没有源码,就无法运用annotation,只能使用xml

12.  @Component@Service @Controller @Repository

a)     初始化的名字默认为类名首字母小写

b)     可以指定初始化bean的名字

13.  @Scope

14.  @PostConstruct= init-method; @PreDestroy = destroy-method;

 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值