1. 关于constructor-arg:
【xml】
<bean name="conService" class="io.lin.common.spring.conarg.ConstructService">
<constructor-arg name="name" value="aaaa"></constructor-arg>
<constructor-arg name="num" value="12"></constructor-arg>
<constructor-arg name="bool" value="true"></constructor-arg>
</bean>
<bean name="prototypeConService" class="io.lin.common.spring.conarg.ConstructService" scope="prototype">
<constructor-arg name="name" value="aaaa"></constructor-arg>
<constructor-arg name="bool" value="true"></constructor-arg>
<constructor-arg name="num" value="12"></constructor-arg>
</bean>
<bean name="lazyConService" class="io.lin.common.spring.conarg.ConstructService" lazy-init="true">
<constructor-arg name="name" value="aaaa"></constructor-arg>
<constructor-arg name="num" value="12"></constructor-arg>
<constructor-arg name="bool" value="true"></constructor-arg>
</bean>
【java】
//test default
ConstructService conService = (ConstructService) context.getBean("conService",new String("xxxx"),new Boolean(true),new Integer(1));
String result = conService.toString();
Assert.assertEquals("aaaa true 12", result);
//test prototype
ConstructService prototypeConService1= (ConstructService) context.getBean("prototypeConService");
String result1 = prototypeConService1.toString();
Assert.assertEquals("aaaa true 12", result1);
ConstructService prototypeConService2 = (ConstructService) context.getBean("prototypeConService",new String("xxxxxxxxx"),new Boolean(true),new Integer(1));
String result2 = prototypeConService2.toString();
Assert.assertEquals("xxxxxxxxx true 1", result2);
//test singleton & lazy-init
ConstructService lazyConService = (ConstructService) context.getBean("lazyConService",new String("rrrr"),new Boolean(true),new Integer(1));
Assert.assertEquals("rrrr true 1", lazyConService.toString());
ConstructService lazyConService2 = (ConstructService) context.getBean("lazyConService");
Assert.assertEquals("rrrr true 1", lazyConService2.toString());
2.context:component-scan
2.1)bean已经写在xml里面,但base-package路径又重复包含该bean。xml重复定义的bean在scan的时候跳过。
2.2)base-package路径及其子路径都会被scan