在Eclipse RCP中应用Spring OSGI 管理bean(一)

经过对OSGI Host的研究,把Equinox、spring osgi等技术整合起来,进行了java系统模块化开发研究。于是,进一步想如何利用spring osgi和Eclipse RCP整合起来应用呢?于是在网上查找响应的资料,不是很多,发现了下面这篇文章,写的非常到位,拷贝如下,为尊重原创作者,标明原始url如下:

http://www.ralfebert.de/blog/eclipsercp/spring_osgi/

在完成实验工程的过程中,遇到了一些问题,进行了整理,是为文章系列二。

 

Spring is not only a helpful framework for the server side, its “Spring Dynamic Modules for OSGi” can be beneficial for Eclipse RCP applications on the client side as well:

  • Spring’s IoC container is the most well known implementation of dependency injection. As inversion of control and dependency injection are very general concepts for structuring software applications, you may want to use it to inject the dependencies of your UI and non-UI client-side components as well.
  • Spring provides a bunch of general-purpose abstractions for other frameworks which are enriched with additional functionality. Some of these might make sense in RCP applications as well. For example, you could use Spring Remoting to communicate with your back-end components.

Getting started

I assume that you know Eclipse RCP and Spring quite well and just want to know how to integrate both.

At first, you need to get the Spring Dynamic Modules plug-ins and add them to your target platform. I recommend keeping those separate in a folder and add a new directory entry to your target definition. You can download all the bundles from the Spring Bundle Repository. I added them to my example target platform as well, so you can look up a list of all required plug-ins or download them as one package: eclipse_rcp_de/spring_osgi.

You should also install the Spring IDE plug-ins in your Eclipse IDE. These help a lot with editing Spring configuration files. The update site is here:

http://dist.springframework.org/release/IDE

Adding Spring application contexts to your bundles

With Spring Dynamic Modules, every bundle gets its own application context. The XML configuration files are added to the folder META-INF/spring/ of your bundle. The naming convention for these files is [module]-context.xml:

de.ralfebert.someplugin
|-- META-INF
|   |-- MANIFEST.MF
|   `-- spring
|       `-- services-context.xml
|-- build.properties
`-- src

If you’ve installed the Spring IDE, you can add the Spring nature to your plug-in (Plug-in project context menu > Spring Tools > Add Spring Project Nature). You can then create the configuration files using New > Spring > Spring Bean Configuration File.

You can read more about the bundle structure in the Spring documentation: Bundle Format And Manifest Headers

Extender

Spring Dynamic Modules comes with a bundle org.springframework.osgi.extender that is responsible for instantiating the Spring application contexts. You need to make sure that this bundle is started, because only then the application contexts for your bundles will be available.

When you run your application from the Eclipse IDE, you can configure start levels in the Plug-ins tab of the run configuration:

Start levels for Spring DM extender in run configuration

For the exported product, you can specify start levels in the Configuration tab of the product. These settings are written to the file config.ini in your application configuration folder. Unfortunately, when you add a start level here, the default start levels are not applied any more (see bug #272768). So you need to configure the start levels of the framework bundles as well. This is the correct configuration for the start levels:

Start levels for Spring DM extender in product

An alternative to the config.ini file is to start the extender programmatically. This can be done by adding the following code in a place that is guaranteed to be used as part of the application startup (for example the Activator of the bundle that contains the RCP application or the Application class itself):

// Enforcing that Spring Dynamic Modules extender is started
Platform.getBundle("org.springframework.osgi.extender").start();

If you updated your run configuration and run your application, you should see the Spring extender startup in the console log:

30.07.2009 19:26:28 org.springframework.osgi.extender.internal.activator.ContextLoaderListener start
INFO: Starting [org.springframework.osgi.extender] bundle v.[1.2.0]
30.07.2009 19:26:28 org.springframework.osgi.extender.internal.support.ExtenderConfiguration <init>
INFO: No custom extender configuration detected; using defaults...

You can read more about the extender in the Spring documentation: The Spring Dynamic Modules Extender bundle

Injecting into view components

At this point, you can use Spring Dynamic Modules to declare beans and inject their dependencies in the same way as on the server-side. But how can you inject dependencies in your view components like View- or EditorParts? To inject their dependencies we need them to be Spring beans. Unfortunately, the Eclipse workbench is responsible for instantiating these objects. How can we delegate this responsibility to the Spring IoC container?

A little detail about the Eclipse extension mechanism comes in handy here. Wherever you can specify a class as attribute of an extension element, you can also specify a factory class (that implements IExecutableExtensionFactory). Then Eclipse will not instantiate the object itself but ask the factory instead.

Martin Lippert wrote a SpringExtensionFactory that will ask the bundle application context for the object. You can read download it below.

After you added the org.eclipse.springframework.util plug-in to your project and imported the package org.eclipse.springframework.util in your bundle manifest, you can use the SpringExtensionFactory like this:

<extension point="org.eclipse.ui.views">
   <view
         id="de.ralfebert.someview"
         class="org.eclipse.springframework.util.SpringExtensionFactory"
         name="SomeView"
         restorable="true">
   </view>
</extension>

The SpringExtensionFactory will look up the bean with the id de.ralfebert.someview and Eclipse will use this object. You can also specify the bean id independently from the id attribute of the contribution element using:

org.eclipse.springframework.util.SpringExtensionFactory:somebeanid

The bean has to be declared in the contributing plug-in. As view components are usually not singletons, you should use Spring’s prototype scope (this will make Spring instantiate a new instance every time this bean is requested):

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="de.ralfebert.someview" class="de.ralfebert.SomeViewPart" scope="prototype"/>
        
</beans>

OSGi services

So far we have seen how to declare application contexts for bundles and how to inject dependencies in view components. Every bundle has its own, separate application context - what if multiple bundles want to act together? This is done using OSGi services.

You can export OSGi services in one bundle and import them in another bundle using a special XML namespace for OSGi:

Exporting a service

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    
    xmlns:osgi="http://www.springframework.org/schema/osgi"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/osgi
        http://www.springframework.org/schema/osgi/spring-osgi.xsd">

    <bean id="someService" class="de.ralfebert.services.internal.SomeServiceImpl"/>

    <osgi:service ref="someService" interface="de.ralfebert.services.ISomeService"/>

</beans>

Importing a service

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:osgi="http://www.springframework.org/schema/osgi"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/osgi
        http://www.springframework.org/schema/osgi/spring-osgi.xsd">

    <osgi:reference id="someService" interface="de.ralfebert.services.ISomeService"/>

</beans>

You can read more about importing and exporting services in the Spring documentation: Exporting A Spring Bean As An OSGi Service, Defining References To OSGi Services

IMX335摄像头原理图设计,已量产 从工程组织上看,IMX335 模组和 IMX415 模组属于同一类产品:核心矛盾不是外设多,而是高速图像链路、电源域和调试接口要同时兼顾。ATK-MCIMX335 这张图的结构也很直接,三路 LDO、本地 24MHz 可选时钟、4-lane MIPI 数据对和一组主板侧标准接口,构成了一张非常典型的量产摄像头子板。 阅读详情

相关推荐

DeepSeek Harness桌面版安装教程:从零配置到实用插件推荐

在AI编程工具逐步普及的今天,开发者越来越关注如何将大模型能力无缝融入日常编码流程。这类工具的核心在于构建一个连接模型服务与本地开发环境的中间层,通过项目级上下文理解、终端指令执行和插件机制,让AI真正成为能动手干活的编程副驾驶。安装配置过程中,环境准备、模型服务连接与工具权限设置是三个关键环节。完成基础搭建后,选择合适的插件能显著提升代码质量与问题排查效率,例如基于代码审查的规范对齐和安全扫描,以及面向运行时日志关联分析与性能告警的诊断工具。本文以DeepSeek Harness桌面版为例,从环境自查、安

weixin_31286719的博客 307

在Eclipse RCP中应用Spring OSGI 管理bean(二)

在文章一中,引用了Ralf Ebert的文章,讲述了整个实现的机制和原理,我在实际的实验工程中,遇到了一些问题,真实的记录下来,为后来者戒。 1、在把org.eclipse.springframework.util插件导入自己的workspace中时,如果没有在自己的eclipse runtime中设置spring bundle的位置,工程会报错,找不到导入的包。于是找到s...

沧海一粟 286

从零到英雄:如何用FPGA和AD9288打造你的第一台便携式示波器

本文详细介绍了如何利用FPGA和AD9288 ADC芯片从零开始打造一台高性能便携式示波器。通过硬件架构设计、高速数据采集系统实现及信号处理与显示系统的开发,读者可以掌握400Msps采样率的实现方法,并了解关键器件选型与系统优化技巧。

jjj34的博客 277

应用spring OSGI管理bean

为尊重原创作者,标明原始url如下: http://bill-xing.iteye.com/blog/1175993 http://www.ralfebert.de/blog/eclipsercp/spring_osgi/ 在完成实验工程的过程中,遇到了一些问题,进行了整理,是为文章系列二。   Spring is not only a helpful framework for the

rengq126的专栏 2179

HIDL概述

HIDL背景 Treble 是 Google Android 团队的一项重大项目,意在 Android 操作系统框架在架构方面的一项重大改变,旨在让制造商以更低的成本更轻松、更快速地将设备更新到新版 Android 系统。Android 7.x 及更早版本中没有正式的供应商接口,因此设备制造商必须更新大量 Android 代码才能将设备更新到新版 Android 系统: 图1 Treble ...

u013357557的专栏 2万+

鼎捷T100—二次开发:客制化联络对象维护作业 aooi350

鼎捷T100二次开发,客制化

weixin_52342654的博客 1132

osgi之blueprint.xml注入bean

摘要 在osgi中服务的使用有多种方式,如使用传统的注册式服务,就是我们之前中example不断使用的使用方式,还是osgi中的声明式服务,还有著名的ipojo等等,但在这里值得花一番笔墨来讲解的应该是blueprint,说到blueprint,务必需要提及一下spring,在个人印象中,spring框架几乎成为了java这么多框架中最为有名的一个,传统上提出的ssh,几乎就只剩下spring一个还

0123456789 2646

ADS笔记,新旧两组仿真数据进行绘图和列表对比

原理图器件参数的不同,怎么进行对比观看,操作如下。

彭辉荣的博客 3868

osgi与流行的框架(spring,struts,hibernate等)的集成

扫扫关注“码农社团”微信公众号 坚持最初的执着,从不曾有半点懈怠,为优秀而努力,为证明自己而活。 2.与流行的JAVA B/S体系架构的集成 了解了基于osgi系统设计的基本思想,进一步来研究osgi与流行的框架(spring,struts,hibernate等)的集成,这里首先讲解一下集成原理。 l解决和spring...

weixin_30596023的博客 372

SRC漏洞挖掘实战指南:从零入门到月入过万的网络安全副业

网络安全的核心在于识别和修复系统缺陷,其中逻辑漏洞与信息泄露是常见的安全风险。其原理在于应用程序在业务逻辑设计或数据处理过程中存在缺陷,导致未授权访问或敏感数据暴露。掌握这些技术对于构建安全的应用体系至关重要,不仅能有效防范攻击,也为安全研究人员提供了将技术能力变现的合法途径。在漏洞赏金(Bug Bounty)和SRC(安全应急响应中心)等应用场景中,白帽子通过系统化的测试方法,挖掘此类漏洞,既能获得经济回报,又能积累宝贵的实战经验。本文聚焦于逻辑漏洞与信息泄露的实战挖掘技巧,为初学者提供清晰的入门路径和效

weixin_28568819的博客 346

2025年GESP3月认证C++五级真题解析

小 A 有 2n 件物品,小 B 和小 C 想从小 A 手上买走这些物品。对于第 i 件物品,小 B 会以 bi 的价格购买,而小 C 会以 ci 的价格购买。对于所有测试点,保证 1 <= T <= 100, 2 <= g < p <= 10^9, g, p 为整数, p 为质数。对于所有测试点,保证 1 <= n <= 10^5, 0 <= bi, ci <= 10^9, bi, ci 为整数。对于另外 50 % 的测试点,保证 n <= 100000, 0 <= bi, ci <= 10^9。

lan_in的博客 1035

Eclipse RCP与Spring OSGi:技术详解与最佳实践

本书由资源的Eclipse专家亲自执笔,并得到了Eclipse官方技术社区的强烈推荐,权威性毋庸置疑!内容全面,系统讲解了利用Eclipse RCP和Spring OSGi开发大规模Java应用的核心技术;实战性强,包含大量易于操作的案例和最佳实践。全书共分3个部分:基础篇(第1~5章)详细介绍了与Eclipse RCP相关的一系列核心概念、Eclipse RCP开发环境的搭建,以及SWT、J...

文献 389

保姆级教程:一步步创建 ABAP Text Table

有朋友反馈,问有没有一个自己动手创建 Text Table 的例子,因为自己没有动手实践过,总觉得心里不踏实。这个行为的语义是,ZAI_TYPE_T 这张表的 AI_TYPE 字段值,不能随便维护,必须是表。然后另一个需要添加的字段是 AI_TYPE 这个字段值对应的文本值,本例笔者采用 SAP 标准的。也是自己创建的,很简单的一个 Data Element,类型为 CHAR,长度为 2.依次给主表的 01,02,03 三个字段值维护对应的描述信息,最后效果如下。按照下面的字段结构,创建另一。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 4273

在Eclipse RCP中应用Spring OSGI 管理bean(一)

eclipse rcp 经过对OSGI Host的研究,把Equinox、spring osgi等技术整合起来,进行了java系统模块化开发研究。于是,进一步想如何利用spring osgi和Eclipse RCP整合起来应用呢?于是在网上查找响应的资料,不是很多,发现了下面这篇文章,写的非常到位,拷贝如下,为尊重原创作者,标明原始url如下: http://www.ralfebe

zhulianhai0927的专栏 903

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

Eclipse RCP 玩转 Spring

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

204

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

1. 什么是Eclipse RCP Application

Eclipse RCP application ,RCP(Rich Client Platform)也就是我们常说的富客户端平台, 是一种基于eclipse platform框架的独立的应用程序。Eclipse 不仅仅是我们耳熟能详的IDE工具,也是一种开发框架,是IBM贡献给全人类宝贵财富。本文将从Eclipse结构方面开始价绍。

菜鸟的告白 2477

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

OSGI 概述

l 什么是模块化 与面向对象一样,模块化的目的也是松耦合,高内聚。我们可以理解为模块化是将对象间的互访做了边界划分,即对一组业务相关的对象进行封装,并且提供可能的更高层次的代码访问隔离机制。   l 物理模块化 VS 逻辑模块化 物理模块化是指应用中的类文件被物理的分割放在不同的模块中,但是每个模块间的互访不受控制,各个模块可以访问模块间的内部对象,只要对象是可访问的。只是是对代码本身进行

LoyalDreamer 1246

再谈OSGi中的Service-Oriented Component Model

之前也写过关于Service-Oriented Component Model的blog了,Service-Oriented Component Model(以下简称SOCM)是OSGi R4中最为重要的改进,SOCM也是切实体现OSGi的动态性的模型,大家在使用SOCM的时候可能会因为受到原有思想的影响而一时无法理解,在这篇blog中将再次的对SOCM进行讲解,以便大家能够更好的理解和进行运用。...

BlueDavy 233

Flink 学习日志 03:自定义一个SourceFunction,完成对Redis中数据的读取

本文介绍了在Flink中自定义SourceFunction读取Redis数据的完整流程:通过Jedis客户端连接WSL2中的Redis服务,编写RedisSource实现循环读取所有Key-value并逐条输出,结合Thread.sleep()实现每秒一条的流式效果。关键步骤包括环境准备、添加Jedis依赖、配置IDEA运行时加载provided依赖,并注意生产环境中应避免使用阻塞的keys *,改用scan命令。最终实现动态读取、实时打印,验证了Flink与Redis的数据集成能力。

木木的学习笔记 405

Jupyter Notebook 安装包下载|单元格分块运行,图表直接内嵌

本文详细介绍Jupyter Notebook的安装与基础使用,推荐通过Anaconda一键安装,省去配置烦恼。文中涵盖Jupyter Notebook的交互式特性、单元格操作、Markdown与代码混合编写、第三方库安装及常用快捷键,帮助新手快速上手,高效完成数据分析、教学演示等任务。

GDShrc的博客 194

从0到打通CICD!SpringBoot+GitLab+Jenkins+Docker完整实验

开源Java编写CI/CD工具;依靠插件扩展能力。核心概念:Job任务、Pipeline流水线、Agent执行节点、Artifact构建产物、Plugin插件。Pipeline阶段:拉取代码 → 编译构建 → 单元测试 → 代码质量扫描 → 打包制品 → 部署测试环境 → 部署生产。IDEA提交代码不要提交.idea目录,会产生冲突。Docker daemon.json不能存在非法url,否则docker启动失败。

2403_87659444的博客 200

学习FreeRTOS推荐哪本书?

第3部分结合硬件实战,讲解基于FreeRTOS开发UART、USB等外设驱动的方法,演示任务、中断、DMA的协同使用,并讲解松耦合架构设计;《FreeRTOS实战:用STM32+SEGGER打造工业级实时嵌入式系统(第2版)》内容由浅入深、理论结合实战,既适合嵌入式系统入门者从零学习RTOS与FreeRTOS开发,也可供具备一定经验的嵌入式工程师参考,用于提升FreeRTOS项目开发、驱动设计与系统调试能力。第14~15章介绍FreeRTOS的内存管理,以及FreeRTOS在多处理器与多核系统中的应用。

人邮异步社区 271

OpenCV学习(一)

本文介绍了OpenCV的基本概念与应用,通过简单代码演示图像灰度转换与人脸检测,展现其“简化复杂视觉任务”的核心优势。OpenCV是开源、跨平台、多语言支持的计算机视觉库,广泛应用于人脸识别、车牌识别、工业检测等领域。文章详细指导了在Windows系统下使用Python 3.12搭建OpenCV开发环境的步骤,包括Python安装、环境变量配置及验证方法,为初学者提供清晰的入门路径。

xiao_suan_cai的博客 179

pycharm如何运行python代码

在PyCharm中运行Python代码的主要步骤包括:安装PyCharm、创建项目、编写Python代码、配置运行环境、执行代码。 首先

2601_96798737的博客 191

计算题验证码怎么自动算出答案?安卓/ios手机开发工具按键精灵OcrEX识别加计算,一套流程全搞定

计算题验证码看似简单,实则常困住脚本自动化开发者。本文详解使用按键精灵安卓版OcrEX组件实现三步破解:精准识别算式、清洗脏数据(如等号、问号、中文运算符)、调用eval或自写函数计算结果。关键技巧包括缩小识别区域、处理全半角差异、利用可信度过滤低质识别,并推荐正则提取标准算式。完整脚本可直接运行,大幅提升自动化成功率。

ii_best的博客 198

【AI编程】使用笔记:修复vscode中codex插件加载失败 Codex could not start

适用于打开 Codex 侧栏后显示,并在日志中确认界面就绪超时的情况。本文将等待时间从延长到。这是针对特定插件版本的临时修改,该版本把时限写在插件程序里,VS Code 的和 Codex 的都没有对应设置项。

tz_zs的博客 326
上一篇: osgi控制台在RCP程序中开发的应用
下一篇: 在Eclipse RCP中应用Spring OSGI 管理bean(二)
tkxing
博客等级 码龄19年 1粉丝 57原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值