Bean Creation in spring - Tutorial Part - 3

Bean Creation :
  • Direct instantiation
    • <bean id=“beanId” class=“className”>
  • BeanFactory instantiation
    • Same syntax but class is subclass of BeanFactory
    • getObject() called to obtain Bean
  • Static Factory
    • <bean id=“beanId” class=“className" factory-method=" staticCreationMethod“>
  • Instance Factory Method
    • <bean id=“beanId” factory-bean=“existingBeanId" factory-method=“nonStaticCreationMethod">
  • Beans may be singletons or “prototypes”
    • Attribute singleton=“false” causes instantiation with each getBean() lookup
    • Singleton is default
  • XmlBeanFactory pre-instantiates singletons
    • May be overridden on per-instance basis by lazy-init=“true”
  • Beans may also be marked abstract, allowing reuse of attribute values through inheritance
Autowiring Properties :
  • Beans may be auto-wired (rather than using <ref>)
    • Per-bean attribute autowire
    • Explicit settings override
  • autowire=“name”
    • Bean identifier matches property name
  • autowire=“type”
    • Type matches other defined bean
  • autowire=”constructor”
    • Match constructor argument types
  • autowire=”autodetect”
    • Attempt by constructor, otherwise “type”
ApplicationContext :
  • Extends functionality of BeanFactory
  • Pre-instantiates singleton beans
  • Detects and registers BeanPostProcessors and BeanFactoryPostProcessors
  • Supports nesting of contexts
  • ApplicationListener and ApplicationEvents
    • Initialized and closed predefined
    • Custom may be created
  • MessageSource provides i18n messaging
    • <bean id=”messageSource” class=”...ResourceBundleMessageSource”/> Contains list of bundle base names.



Enter your email address to get our daily JOBS & INTERVIEW FAQ's Straight to your Inbox.

Make sure to activate your subscription by clicking on the activation link sent to your email