你的位置:首页 > 软件开发 > Java > [转载]Difference between context:annotation

[转载]Difference between context:annotation

发布时间:2015-09-01 21:00:10
在国外看到详细的说明一篇,非常浅显透彻。转给国内的筒子们:-) 原文标题:Spring中的<context:annotation-config>与<context:component-scan>到底有什么不同? 原文出处:http://stacko ...

在国外看到详细的说明一篇,非常浅显透彻。转给国内的筒子们:-)

 

原文标题:

Spring中的<context:annotation-config>与<context:component-scan>到底有什么不同?

 

原文出处:http://stackoverflow.com/a/7456501

 

<context:annotation-config> is used to activate annotations in beans already registered in the application context (no matter if they were defined with

<context:component-scan> can also do what <context:annotation-config> does but <context:component-scan> also scans packages to find and register beans within the application context.

I'll use some examples to show the differences/similarities.

Lets start with a basic setup of three beans of type AB and C, with B and C being injected into A.

 1 package com.xxx; 2 public class B { 3  public B() { 4   System.out.println("creating bean B: " + this); 5  } 6 } 7  8 package com.xxx; 9 public class C {10  public C() {11   System.out.println("creating bean C: " + this);12  }13 }14 15 package com.yyy;16 import com.xxx.B;17 import com.xxx.C;18 public class A { 19  private B bbb;20  private C ccc;21  public A() {22   System.out.println("creating bean A: " + this);23  }24  public void setBbb(B bbb) {25   System.out.println("setting A.bbb with " + bbb);26   this.bbb = bbb;27  }28  public void setCcc(C ccc) {29   System.out.println("setting A.ccc with " + ccc);30   this.ccc = ccc; 31  }32 }

 

海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com

原标题:[转载]Difference between context:annotation

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录