Frank, This is probably not the answer you looking for, but I have to just throw in my two cents. When should you use @Component? Never. The cleanest way to use the Spring container is to *never* "import org.springframework". Only bootstrap and obviously spring specific code should import spring packages. JSR250 and JSR330 provide standards compliant annotations that can be used in place of the Spring one's that give most of all the functionality. Refer to http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/beans.html#beans-standard-annotations. The standard compliant annotation of @Component would be @Named from JSR250 (which is included in the JDK at this point).
Regarding when to use @Named and when to register the bean in XML. You should never use @Named. I'm sure many will disagree with me but past experiences have over and over again shown to me that component scanning on large scale projects is a bad idea. Ignoring bad initialization performance, component scanning ends up introducing weird difficult to debug issues when some does something dumb. It is better to have a clear and definitive source regarding what is registered in your context. Additionally if you get into context hierarchies (which I hope you do, but that is a different topic altogether), component scanning blows up. Darren -------- Original Message -------- Subject: what's rule for using @Component and xml bean file From: Frank Zhang <frank.zh...@citrix.com> Date: Fri, February 08, 2013 6:39 pm To: "cloudstack-dev@incubator.apache.org" <cloudstack-dev@incubator.apache.org> I see client/tomcatconf/componentContext.xml.in defining lots of beans while I also see many beans use @Component Is there any guideline here?