求教:注入的具體實現類是哪一個?

hellodidang發表於2012-07-15
先看主要程式碼:

// 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修改過]

相關文章