[英]How can i get my Application Context in xml defination while working in Spring Boot
什么是 xml 等價物
@Autowired
private ApplicationContext appContext;
?
PS:當我嘗試用谷歌搜索它時,我得到了一百萬個關於 ApplicationContext 如何工作的結果,但沒有得到如何在 xml 定義中獲取它的結果。 該項目都是使用xml定義編寫的,所以我需要找到一種沒有注釋的方法。
首先,在文件 applicationContext.xml 中配置你的 spring beans 例如:-
<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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.