Ray's playground

 

Basic bean wiring(Chapter 2 of Spring In Action)

  There is no single Spring container. Spring comes with several container implementations that can be categorized into two distinct types. Bean factories (defined by the org.springframework.beans.factory.BeanFactory interface) are the simplest of containers, providing basic support for DI. Application contexts (defined by the org.springframework.context.ApplicationContext interface) build on the notion of a bean factory by providing application framework services, such as the ability to resolve textual messages from a properties file and the ability to publish application events to interested event listeners.

  Spring provides four flavors of autowiring:

  ■ byName—Attempts to find a bean in the container whose name (or ID) is the same as the name of the property being wired. If a matching bean is not

found, the property will remain unwired.

  ■ byType—Attempts to find a single bean in the container whose type matches the type of the property being wired. If no matching bean is found,

the property will not be wired. If more than one bean matches, an org.springframework.beans.factory.UnsatisfiedDependencyException will be thrown.

  ■ constructor—Tries to match up one or more beans in the container with the parameters of one of the constructors of the bean being wired. In the

event of ambiguous beans or ambiguous constructors, an org.springframework.beans.factory.UnsatisfiedDependencyException will be thrown.

  ■ autodetect—Attempts to autowire by constructor first and then using byType. Ambiguity is handled the same way as with constructor and byType wiring. 

 

   

posted on 2010-06-20 19:16  Ray Z  阅读(298)  评论(0编辑  收藏  举报

导航