Spring(1)基础概念

 

1、Test Disk

MoveDisk

UsbDisk

applicationContext.xml头文件

 <bean name="disk" class="dao.impl.MoveDisk">

 

public class test extends TestCase{

ApplicationContext ctx=new 

 

ClassPathXmlApplicationContext("applicationContext.xml");

Disk disk=(Disk)ctx.getBean("disk");

}

 

2、注入

 

<!--setter-->

<bean name="sService" class="dao.imple.StudentService">

<property name="sid" value="S001"/>

<property name="sname" value="流弊"/>

<property name="sage" value="25"/>

 

<!--constructor-->

<bean name="sService" class="dao.imple.StudentService">

<constructor-arg index="0" value="S001"/>

<constructor-arg index="1" value="流弊"/>

<constructor-arg index="2" value="25"/>

 

@Resource

 

@Autowise

@Qulified

 

联系

<bean name="s" class="StudentsDao">

<bean name="sService" class="dao.imple.StudentService">

<propert name="sDao" bean="s">

 

<bean name="s" class="StudentsDao">

<bean name="sService" class="dao.imple.StudentService">

<propert name="sDao" ref="s">

 

 

3、Set、List、Map

 

<List>

<value></value>

<value></value>

</List>

<List>

<bean></bean>

<bean></bean>

</List>

 

<Set>

 

</Set>

 

<Map>

 

4、类型转换问题

 

(1)BeanFactory solution

<bean id="dateFormat" class="java.text.SimpleDateFormat">  

        <constructor-arg value="yyyy-MM-dd" />  

    </bean>  

 

<bean>

 <property name="birthday">  

            <bean factory-bean="dateFormat" factory-method="parse">  

              <constructor-arg value="2010-01-31" />  

            </bean>  

          </property>

</bean>

 

 

5、Bean生存范围

Singleton:默认、引用出来两个例子实际为同一地址。

Student s1=(Student).getBean("student");

Student s2=(Student).getBean("student");

s1==s2为true;

Prototype 

s1==s2为false;

 

lazy-init="true"

调用程序才初始化然后加载

 

init-method="类内方法名"

/destroy-method="类内方法名"

 

depends-on/实例化这个bean之前要先实例化on后的bean

 

id等价于Java变量命名,不能出现两个id

name没有限定,可以出现多个 只返回后面的 且可以name="stu,student"

 

无类名情况

<bean class=1>

<bean class=1>

<bean class=1>

getBean("1#0");

getBean("1#1");

getBean("1#2");

 

6、Abstract Bean

<bean id="person" abstract="true"

class="dao.Person2">

<property name="name" value="降龙"/>

</bean>

 

<bean id="student" class="dao.impl.Student"

parent="person">

</bean>

 

person无法实例化,只能为student提供模板

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值