应用程序中的每个类应如何检索Spring应用程序上下文?

Der*_*har 0 java spring

应用程序中的每个类应如何检索Spring应用程序上下文?或者,换句话说,应用程序应该调用多少次new ClassPathXmlApplicationContext("applicationContext.xml")

ext*_*eon 5

通常一个类不需要应用程序上下文,但它需要一些Spring注入的对象.这是在applicationContext中配置的.

因此,应用程序通常new ClassPathXmlApplicationContext("applicationContext.xml")只调用一次.