【问题标题】:Where created ApplicationContext in web project?在 Web 项目中创建 ApplicationContext 的位置?
【发布时间】:2014-10-02 14:51:39
【问题描述】:

有一些示例项目的代码(不使用 servlet):

ApplicationContext ctx = 
                new ClassPathXmlApplicationContext("spring.xml");
ExampleBean exampleBean = (ExampleBean) ctx.getBean("exampleBean");
System.out.println(exampleBean.sayHello());

我明白了,我们直接创建 ApplicationContext 并从中获取 bean。 但在 servlet 的示例中,我没有找到 ApplicationContext 的创建位置。

谁能这么说?

谢谢。

【问题讨论】:

    标签: java spring inversion-of-control


    【解决方案1】:

    应用程序(非必需)ApplicationcContextContextLoaderListener 创建。

    Servlet(必需)ApplicationContextDispatcherServlet 创建,如果存在,则使用 ContextLoaderListenerApplicationContext 作为父级。

    【讨论】:

    • 如果它不存在呢?
    • @qwerre 不用了。
    猜你喜欢
    • 2020-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-30
    • 1970-01-01
    • 2012-12-22
    • 1970-01-01
    • 2021-02-25
    相关资源
    最近更新 更多