`
ytuwlg
  • 浏览: 91156 次
  • 性别: Icon_minigender_1
  • 来自: 威海
社区版块
存档分类
最新评论

spring: application context vs bean factory

    博客分类:
  • java
阅读更多

      bean factory to read the bean definitions from the Resource. But the bean factory doesn’t instantiate the beans just yet. Beans are “lazily” loaded into bean factories, meaning that while the bean factory will immediately load the bean definitions (the description of beans and their properties),

the beans themselves will not be instantiated until they are needed.


     When getBean() is called, the factory will instantiate the bean and set the bean’s properties using DI. Thus begins the life of a bean within the Spring container.


     A bean factory is fine for simple applications, but to take advantage of the full power of the Spring Framework, you’ll probably want to load your application beans using Spring’s more advanced container: the application context.


    On the surface, an ApplicationContext is much the same as a BeanFactory. Both load bean definitions, wire beans together, and dispense beans upon request. But an ApplicationContext offers much more:

 

      ■ Application contexts provide a means for resolving text messages, including support for internationalization (I18N) of those messages.


      ■ Application contexts provide a generic way to load file resources, such as images.


      ■ Application contexts can publish events to beans that are registered as listeners.


Because of the additional functionality it provides, an ApplicationContext is preferred over a BeanFactory in nearly all applications. The only times you might consider using a BeanFactory are in circumstances where resources are scarce, such as a mobile device. We will be using an ApplicationContext

    

     Aside from the additional functionality offered by application contexts,another big difference between an application context and a bean factory is how singleton beans are loaded. A bean factory lazily loads all beans, deferring bean creation until the getBean() method is called. An application context is a bit smarter and preloads all singleton beans upon context startup. By preloading singleton beans, you ensure that they will be ready to use when needed—your application won’t have to wait for them to be created.

分享到:
评论

相关推荐

    testSpring

    信息: Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext@c1f10e]: org.springframework.beans.factory.support.DefaultListableBeanFactory@15e234c ...

    spring applicationContext 配置文件

    <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean" p:dataSource-ref="dataSourceProxy"> <value>classpath:SqlMapConfig.xml</value> </property> </bean...

    ssh框架在application.xml中配置数据源所需jar

    - Application context definition for JPetStore's business layer. - Contains bean references to the transaction manager and to the DAOs in - dataAccessContext-local/jta.xml (see web.xml's ...

    Manning.Spring.in.Action.4th.Edition.2014.11.epub

    1.2.1. Working with an application context 1.2.2. A bean’s life 1.3. Surveying the Spring landscape 1.3.1. Spring modules 1.3.2. The Spring portfolio 1.4. What’s new in Spring 1.4.1. What was new in...

    SPRING API 2.0.CHM

    ApplicationListener ApplicationObjectSupport ArgPreparedStatementSetter ArgTypePreparedStatementSetter ArgumentConvertingMethodInvoker AspectComponentDefinition AspectEntry ...

    spring3.2+strut2+hibernate4

    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <value>classpath*:jdbc.properties </bean> <!-- 数据源配置,主要用于...

    Red5 0.9与现有tomcat项目整合

    <bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> </bean> <!-- ROOT web context --> <bean id="myApp.context" class="org.red5.server....

    swing界面设计之JTree

    创建 Spring app-context.xml bean 定义文件 19 运行应用程序 20 定义 bean 属性 21 创建 to-do 列表:创建一个可重用组件并在表中显示数据 23 创建一个可重用的面板 23 将 bean 组合在一起 24 添加一个表并重用这个...

    spring-framework-reference-4.1.2

    Aliasing a bean outside the bean definition ................................................ 28 Instantiating beans .......................................................................................

    +Flex+集成到+Java+EE+应用程序的最佳实践(完整源代码)

    log.info("Lookup bean from Spring ApplicationContext: " + beanName); return appContext.getBean(beanName); } catch (NoSuchBeanDefinitionException nex) { ... } catch (BeansException bex) { ...

    将 Flex 集成到 Java EE 应用程序的最佳实践(完整源代码)

    log.info("Lookup bean from Spring ApplicationContext: " + beanName); return appContext.getBean(beanName); } catch (NoSuchBeanDefinitionException nex) { ... } catch (BeansException bex) { ...

    spring-framework-reference4.1.4

    Aliasing a bean outside the bean definition ................................................ 28 Instantiating beans .......................................................................................

    JBoss Seam 工作原理、seam和hibernate的范例、RESTFul的seam、seam-gen起步、seam组件、配置组件、jsf,jboss、标签、PDF、注解等等

    Seam - 语境相关的组件[满江红20071230]............................................................................................................................ 1 Java EE 框架...........................

Global site tag (gtag.js) - Google Analytics