先看主要代码:
// SampleAppTest.java
public void testGet[author]Service[/author]() {
BInterface b = (BInterface) appUtil.get[author]Service[/author]("b");
Assert.assertEquals(b.bMethod(1), 10);
}
//B.java
@[author]Service[/author]("b")
public class B implements BInterface {
AInterface a;
DInterface d;
public B(AInterface a, DInterface d) {
this.a = a;
this.d = d;
}
public int bMethod(int i) {
System.out.println("call A.myMethod1 ");
i++;
i = (Integer) a.myMethod(i, null);
System.out.print("\n\n call A.myMethod1 result=" + i + " \n\n");
i++;
System.out.println("call A.myMethod2 ");
i = (Integer) a.myMethod2(i);
System.out.print("\n\n call A.myMethod2 result=" + i + "\n\n");
i++;
return (Integer) d.myMethod3(i);
}
}
<p class="indent">
|
疑问:实例化B时,会自动注入AInterface、DInterface,但框架是怎么知道具体注入哪个实现类,从哪里体现出来?求教,谢谢!!!
[该贴被hellodidang于2012-07-15 09:59修改过]
[该贴被hellodidang于2012-07-15 10:02修改过]
[该贴被hellodidang于2012-07-15 10:02修改过]
[该贴被hellodidang于2012-07-15 10:03修改过]