eclipse RPC加载Spring 容器

加载语句如下:

。。。。。
 static BeanFactory beanFactory;
  public void start(BundleContext context) throws Exception {
  super.start(context);
  initSpring();
  plugin = this;
 }

  private void initSpring() {
  ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
  try {
   Object o = this.getClass().getClassLoader();
   Thread.currentThread().setContextClassLoader((ClassLoader) o);
   beanFactory = new ClassPathXmlApplicationContext(
     "/applicationContext.xml");
  } finally {
   Thread.currentThread().setContextClassLoader(oldLoader);
  }

 }

 public static BeanFactory getBeanFactory() {
  return beanFactory;
 }

以上内容加入后:

将改语句放在了Activator的start里。因为RCP是延迟加载,需要使用Spring容器的时候,所需要的包还未加载。因此,要将以上语句放在Activator插件加载之前,实现立即加载。新建一个类实现IStartup家口。加载RCP扩展点。

 

Spring的配置文件中的头部:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-2.5.xsd">

 

由于不能连接外网而找不到XSD文件,但是加载的Spring.jar包中有,系统却关联不上(该RCP工程,将所有要使用的jar包都放在了一个同意的插件中)。此处是因为,虽然第三方包的插件的jar所有的都暴露给了其他的插件,但是spring.handlers却找不到,所以,只能将spring.jar包放到使用spring配置文件的插件中

   在PLUGIN.XML中RUNTIME加入classpath中加入JAR包.

 

,从而才能解决这个问题。

 

posted @ 2010-08-28 15:04  夜色狼  阅读(624)  评论(4编辑  收藏  举报