近来上一个项目想在Eclipse RCP中使用Spring,在网上Google了一下发现这方面的材料比较少,晓得Spring自个有个Spring-OSGI的项目,能够在Spring中装备OSGI效劳。但是,我仅仅想在RCP中引进Spring来管理Java Bean,不想去研讨那个东西。所以,看看有没有啥简略的方法来处理这个疑问。
所以,我在RCP项目的activator class中加入了

 
private ApplicationContext ctx;
2
3     private void initializeApplicationContext() {
4         ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
5         try{
6             Thread.currentThread().setContextClassLoader(getDefault().getClass().getClassLoader());
7             this.ctx = new FileSystemXmlApplicationContext(ProjectUtil.toFullPath("properties/applicationContext.xml"));
8         } finally {
9             Thread.currentThread().setContextClassLoader(oldLoader);
10         }
11     }