Spring的基础入门知识3

Spring自动装配

1,byname (autowire=“byname”)

根据指定的名称来进行装配

2,byType(autowire=“byType”)

自动匹配相关的类型

3,constructor(autowire=“constructor”)

通过构造函数的形式来进行装配

4,autodectect(autowire=“autodectect”)

默认通过构造函数的形式来进行装配,如果不行则通过byType的形式

5,no(autowire=“no”)

使用property的参数来进行装配

Spring对依赖进行检查

Simple:

对未进行指定指定依赖的对象进行检查

Object:

对指定的依赖对象进行检查

All:

对全部的对象进行检查

None:

对全部的对象都不检查

Spring集合注入方式

List,set,map,properties,都是在<property></ property >进行注入

List注入:

<list>

<value>hello</value>

<value>word</value>

</list>

Set注入:(和list极度类似)

<set>

<value>hello</value>

<value>word</value>

</set>

Map注入:

<map>

<entry key=”name”>

<value>moon.l</value>

</entry>

</map>

Proprties注入:

<props>

<prop key=”name”>moon.l</prop>

</props>

说明:都是将节点注入到集合当中,让后再将集合注入到bean中去

Spring对Bean的管理方式

使用BeanWrapper:

HelloWord hw = new HelloWord();

BeanWrapper  bw  = new BeanWrapperImpl(hw);

Bw.setPropertyValue(key,value);

通过实现BeanWrapperImpl的实现对Bean对象的管理

使用BeanFactoty:

ClassPathResource res = new ClassPathResource("application.xml");

BeanFactory bf = new XmlBeanFactory(res);

bf.getBean("");

使用ApplicationContext

ApplicationContext ctx = new FileSystemXmlApplicationContext("application.xml")

ctx.getBean("");

说明:常用BeanFactoty、和ApplicationContext,但是ApplicationContext的功能更强大,可以理解成BeanFactoty超集。

猜你喜欢

转载自liaoyue11.iteye.com/blog/2355817
今日推荐