Java Spring multiple ApplicationContext

前端 未结 6 1752
一生所求
一生所求 2020-12-07 14:51

The definition of the spring ApplicationContext is very ambiguous, I almost finish a whole book of tutorial but still cannot understand what is the Applic

6条回答
  •  爱一瞬间的悲伤
    2020-12-07 15:44

    I keep seeing the book mentioned "container", what is the container refer to? One container does it mean one java process? or one container refer to one ApplicationContext object?

    Here container means spring container which is nothing but ApplicationContext. This internally reads spring configuration and loads the classes based on configuration. You may think it as SpringProcessor which provides the various functionality like bean initialization, injection, i18n, bean Post processing etc off the shelf

    with

    ApplicationContext context1 = new ClassPathXmlApplicationContext("Beans.xml"); ApplicationContext context2 = new ClassPathXmlApplicationContext("Beans.xml");

    There will be two conatiners , hence two singleton beans. Here singleton means singleton instance per container. Ideally you should have only one container until and unless you have a reason for two. For learning purpose it makes sense to understand the concepts

提交回复
热议问题