我怎么能得到我的应用程序上下文在xml定义,而在春季启动工作



@Autowired
private ApplicationContext appContext;
?

注::当我试图谷歌它我得到了关于ApplicationContext如何工作的一百万结果,但不是如何在xml定义中得到它。该项目都是使用xml定义编写的,所以我需要找到一种方法,如何做到没有注释。

首先,在applicationContext.xml文件中配置spring bean,例如:-

<bean id="beanId"
class="com.java.spring.MyClassName">
</bean>

加载spring配置文件并从spring容器中检索bean

ClassPathXmlApplicationContext context = 
new ClassPathXmlApplicationContext("applicationContext.xml");

MyClass myBean = context.getBean("beanId",MyClass.class);

相关内容

最新更新