Eclipse RCP入门(四)集成SPRING

Eclipse RCP入门(四)

在RCP中使用spring
http://sourceforge.net/project/showfiles.php?group_id=145348


前人已经写了这个开源包了。下载过来。
把JAR包:
net.sourceforge.eclipsespring_0.1.0.jar
net.sourceforge.eclipsespring.example_0.1.0.jar
放在eclipse下面的plugins下面。嘿嘿。example其实可以不放。

打开plugin.xml文件
把如下内容加入
point="net.sourceforge.eclipsespring.beanFactoryContributors">
class="com.sillycat.rcp.BeanFactoryContributor"
id="sillycatGen"/>

扩展调用SPRING的XML配置文件
修改了VIEW的定义:
category="sillycatGen"
class="net.sourceforge.eclipsespring.SpringExtensionFactory:sillycatGen/SampleView"
icon="icons/sample.gif"
id="com.sillycat.views.SampleView"
name="MainWindow">

注意其中的net.sourceforge.eclipsespring.SpringExtensionFactory:sillycatGen/SampleView中的
sillycatGen和最先定义的extension里面的ID保持一致

plugin.xml的全文如下:




point="net.sourceforge.eclipsespring.beanFactoryContributors">
class="com.sillycat.rcp.BeanFactoryContributor"
id="sillycatGen"/>


id="application"
point="org.eclipse.core.runtime.applications">

class="com.sillycat.rcp.Application">



point="org.eclipse.ui.perspectives">
name="RCP Perspective"
class="com.sillycat.rcp.Perspective"
id="sillycatGen.perspective">


id="product"
point="org.eclipse.core.runtime.products">
【Eclipse RCP入门(四)集成SPRING】 application="sillycatGen.application"
name="sillycatGen">
name="appName"
value="https://www.it610.com/article/sillycatGen">



point="org.eclipse.ui.views">
category="sillycatGen"
class="net.sourceforge.eclipsespring.SpringExtensionFactory:sillycatGen/SampleView"
icon="icons/sample.gif"
id="com.sillycat.views.SampleView"
name="MainWindow">


point="org.eclipse.ui.perspectiveExtensions">
targetID="org.eclipse.ui.resourcePerspective">
id="com.sillycat.views.SampleView"
ratio="0.5"
relationship="right"
relative="org.eclipse.ui.views.TaskList">







在plugin.xml的Dependencies中加入:
net.sourceforge.eclipsespring
org.springframework
org.apache.commons.logging

在sillycatGen.product定义文件的Configuration中也加入:
net.sourceforge.eclipsespring
org.apache.commons.logging
org.springframework

另外在plugin.xml中的BeanFactoryContributor.java如下:
package com.sillycat.rcp;

import net.sourceforge.eclipsespring.util.AbstractBeanFactoryContributor;

public class BeanFactoryContributor extends AbstractBeanFactoryContributor {

protected String[] getResourcePaths() {
return new String[] { "/applicationContext.xml" };
}
}

spring的配置文件applicationContext.xml如下:














userManager是个例子,UserManagerImpl.java如下:
package com.sillycat.services.impl;

import com.sillycat.services.UserManager;

public class UserManagerImpl implements UserManager {

public String getCurrentUserName() {
return System.getProperty("user.name");
}

}

    推荐阅读