Eclipse RCP + Spring with Hibernate flavor
来源:互联网 发布:河北三金网络怎么样 编辑:程序博客网 时间:2024/06/07 20:09
本文翻译自 Eclipse RCP + Spring with Hibernate flavor 一文,文章版权归原作者所有
本文来自: Alpha Atom
译者: Samuel Chen
public class MyPlugin extends AbstractUIPlugin {
private ApplicationContext applicationContext;
private static final String[] SPRING_CONFIGS = {
"/applicationContext.xml",
"/applicationContextDatabase.xml"
};
public void start(BundleContext context) throws Exception {
super.start(context);
ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(
this.getClass().getClassLoader());
applicationContext = new ClassPathXmlApplicationContext(SPRING_CONFIGS);
} finally {
Thread.currentThread().setContextClassLoader(oldLoader);
}
}
public ApplicationContext getApplicationContext() {
return applicationContext;
}
/* ... */
}
然后,你可以简单的通过调用得到Spring context。
MyPlugin.getDefault().getApplicationContext()
当然,设定我们自己的classloader不是太好,但是至少会没有问题,例如,Hibernate。那么我们现在定义一些beans:
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>system.properties</value>
</list>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate.LocalSessionFactoryBean"
lazy-init="true">
<property name="mappingJarLocations">
<list>
<value>${hibernate.hbms}</value>
</list>
</property>
</bean>
Now, if you run your application as standalone RCP (via eclipse.exe) then set ${hibernate.hbms} property like this:
现在,如果你将你的应用作为单独的RCP(通过 eclipse.exe)运行,那么就象下面这样设定${hibernate.hbms} :
hibernate.hbms = file:plugins/plugin_1.0.0/project-hbm.jar
路径应该是和你的RCP应用目录的相对路径。如果你计划在Eclipse里面测试你的应用,那么${hibernate.hbms}应该被设置成绝对路径,就像这样:
hibernate.hbms = file:/work/project/lib/project-hbm.jar
在Eclipse 中运行你的应用需要确定,Spring的配置文件在你项目的classpath中。如果你不想将他们和你的java类放到一起(就像我一样),你可以选择 “Allow output folders for source folders"(项目属性,Java编译路径标签),将目录添加到设置并且将其输出目录设定为自身(如果有时你计划清除你的workspace,这将会有一点危险。 :-) )最后一件要记住的事是在你项目属性的“Self-Hosting"标签中打开这个最新添加的目录。
如果你知道更好的方法来集成Spring与Eclipse RCP请告诉我。
- Eclipse RCP + Spring with Hibernate flavor
- Eclipse RCP + Spring with Hibernate flavor
- 在Eclipse RCP中使用Spring或者Hibernate
- 实践Eclipse RCP +Spring
- RCP+Spring+Hibernate的基本总结
- Agile Java Development with Spring, Hibernate and Eclipse
- Hibernate Tools with Eclipse
- Hibernate tutorial with Eclipse
- Hibernate with Spring
- Eclipse RCP
- Eclipse RCP
- eclipse RCP
- RCP Eclipse
- Working with Hibernate in Eclipse
- eclipse(springmvc+spring+hibernate)
- 在Eclipse RCP中使用Spring AOP/ProxyFactory的问题
- Eclipse RCP+Spring建胖客户端Web程序
- eclipse rcp导出乱码以及引入spring配置文件
- 2005年国内各大IT公司的薪酬情况
- 北京一日行之四——德胜门、汇通祠、徐悲鸿纪念馆、梅兰芳纪念馆、恭王府
- 高数考完了
- 谈谈Unicode编码,简要解释UCS、UTF、BMP、BOM等名词
- toby'blog
- Eclipse RCP + Spring with Hibernate flavor
- 梦醒了
- Tomcat与Java Web
- 关于在VC++ 的MFC 下INI文件的生成和运用
- chm文档打开后出现乱码
- Eclipse中Sysdeo Tomcat插件的配置与使用
- 使用links方式安装Eclipse插件
- 如何用正确的方法来写出质量好的软件的75条体会 [转]
- 2004上半年中国最好的WEB技术资源站点排行