spring learn experience

Spring框架配置与依赖注入
本文介绍了Spring框架的配置方式及依赖注入的多种实现方法,包括普通实例化、静态工厂实例化和工厂实例化等,并探讨了注解自动扫描、反射与内省的区别以及双重检查锁定模式。

  • org.springframework.context-3.1.0.M2.jar
  • org.springframework.beans-3.1.0.M2.jar
  • dist\org.springframework.core-3.1.0.M2.jar
  • commons-logging-1.1.1.jar
  • dist\org.springframework.asm-3.1.0.M2.jar
  • dist\org.springframework.expression-3.1.0.M2.jar
  • commons-beanutils-1.8.0.jar
  • dom4j

  • Introspector   java.beans.Introspector

http://www.kaifa6.com/v/J2SEApi/javaref/jdkref/java.beans.introspector_dsc.htm#getBeanInfo(java.lang.Class, java.lang.Class)


  • ConvertUtils.convert("1232a", Integer.class);    org.apache.commons.beanutils.ConvertUtils
<?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-3.0.xsd
           http://www.springframework.org/schema/context 
           http://www.springframework.org/schema/context/spring-context-3.0.xsd
           ">

<!-- for annotation should quote the three line above and a line below -->
	<context:annotation-config/>

<!-- id can not been named as special character ,but name does -->
<!-- 1. normal instance of bean-->
  <bean id="personService" class="beans.PersonServiceBean">
  	<property name="personDao" ref="personDao"></property>
  	<property name="testName" value="James"/>
  	<property name="sets">
  		<set>
  			<value>a</value>
  			<value>b</value>
  			<value>c</value>
  		</set>
  	</property>
  	<property name="lists">
  		<list>
  			<value>a</value>
  			<value>b</value>
  			<value>c</value>
  			<bean class="interfaces.PersonServiceFactory" />
  			<bean class="beans.PersonDaoBean"/>
  		</list>
  	</property>
  	
  	<property name="maps">  
  		<map>
  			<entry key="3" value="personDao"/>
		    <entry key="1" value-ref="personDao"/>
		    <entry key="2" value-ref="personDao"/>
	   </map>
  		
  	</property>
  	<property name="properties">
  		<props>
  			<prop key="age">11</prop>
  		</props>
  	</property>
  </bean>
  <bean id="personDao" class="beans.PersonDaoBean">
  </bean>
	
<!-- 2. static factory instance of bean-->
  <bean id="personService2" class="interfaces.PersonServiceFactory" factory-method="createFactory"/>
  
<!-- 3. factory instance of bean-->
  <bean id="personServiceFactory" class="interfaces.PersonServiceFactory"/>
  <bean id="personService3" factory-bean="personServiceFactory" factory-method="createFactory2"/>
<!--   <bean id="personService3" factory-bean="personServiceFactory" factory-method="createFactory2" scope="prototype"/> -->
</beans>

  <?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-3.0.xsd
           http://www.springframework.org/schema/context 
           http://www.springframework.org/schema/context/spring-context-3.0.xsd
           ">
<!-- FOR AUTO INJECT IN CLASS FILES -->
	  <context:component-scan base-package="beans"/>
</beans>
 

 

 

 

  • differences between Reflect and Introspector

 

 

 

  • Automatically detecting classes and registering bean definitions

@Service @Repository @Controller
@Scope .....

 

 

 

double checked lock 

http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值