[英]access Spring context in OSGi bundle
我有一個OSGi包,它使用bundle-context.xml文件來初始化bean。
<bean id="myBean" class="test.MyClass">
<property name="output" value="test"/>
</bean>
我有一個需要獲取bean實例的工廠類。 在非OSGI世界中,我總是只需要以下內容來初始化上下文並獲取bean的句柄...
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("bundle-context.xml");
MyClass bean = (MyClass) applicationContext.getBean("myBean");
但是,在OSGI(FuseESB 4.2,Servicemix4)中,容器會自動加載bundle-context.xml文件並初始化spring上下文。 如果我顯式加載上下文(使用上面的代碼),則會創建2個上下文(這是不好的)。 那么,獲取相同上下文/ bean的句柄的正確方法是什么?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.