什么是 xml 等價物
@Autowired
private ApplicationContext appContext;
?
PS:當我嘗試用谷歌搜索它時,我得到了一百萬個關于 ApplicationContext 如何作業的結果,但沒有得到如何在 xml 定義中獲取它的結果。該專案都是使用xml定義撰寫的,所以我需要找到一種沒有注釋的方法。
uj5u.com熱心網友回復:
首先,在檔案 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);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/341028.html
