- 浏览: 102474 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
Tom.X:
http://osgia.com
OSGI下的web应用开发(5) -
xiaohei520104:
楼组辛苦了,关于OSGi web的demo资料很少,非常感谢你 ...
OSGI下的web应用开发(5) -
shenwu33:
为什么我的server下面 没有eclipseRT
OSGI下的web应用开发(1) -
zhaoweisgz:
谢谢你的共享~
基于virgo环境的OSGI+Maven的web开发代码下载(spring+hibernate+GWT) -
zrz_1989:
楼主我想请教您个问题,如果将项目移植到OSGi平台上,对于we ...
OSGI下的web应用开发(7)
这一节进入Service Interface Bundle和Service Implementation Bundle的开发。
同样的,首先先来看看类图
为了简化对service的操作,一样定义了一个基础服务接口。
- Service Interface Bundle
(1)新建Bundle Project项目
当项目创建完后,我们需要先把项目间的关联关系设定好再开始编码。如图
勾选上dao2和domain两个项目,因为我们会引用到这两个项目的类。
(2)代码
(2.1) IBaseService
package net.georgezeng.test.service; import java.util.List; public interface IBaseService<T> { void save(T t); T get(Long id); List<T> findList(T t); }
(2.2)ContactService
package net.georgezeng.test.service; import net.georgezeng.test.domain.Contact; public interface ContactService extends IBaseService<Contact> { }
(3)MANIFEST.MF的定义
(3.1)import
(3.2)export
这样Service Interface Bundle就开发完成了
- Service Implementation Bundle
引入了3个关联的项目,分别是dao2,domain和service
package net.georgezeng.test.service.impl; import java.util.List; import net.georgezeng.test.dao.BaseDao; import net.georgezeng.test.service.IBaseService; public abstract class BaseService<T> implements IBaseService<T> { @Override public void save(T t) { getBaseDao().save(t); } @Override public T get(Long id) { return getBaseDao().get(id); } @Override public List<T> findList(T t) { return getBaseDao().findList(t); } protected abstract BaseDao<T> getBaseDao(); }
(2.2)ContactServiceImpl
package net.georgezeng.test.contact.service; import net.georgezeng.test.dao.BaseDao; import net.georgezeng.test.dao.ContactDao; import net.georgezeng.test.domain.Contact; import net.georgezeng.test.service.ContactService; import net.georgezeng.test.service.impl.BaseService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @Service("ContactService") @Transactional public class ContactServiceImpl extends BaseService<Contact> implements ContactService { @Autowired private ContactDao dao; @Override protected BaseDao<Contact> getBaseDao() { return dao; } }
这里使用事务管理使用的是annotation的形式,并且需要在@Service中添加一个ContactService的值,同样也是用于通过spring来发布这个服务时作为引用的bean id。
在上一节中我们还曝露了一个ContactDao的服务,这个地方引用这个服务在代码里是不需要做任何的改变的,因为这个服务的引用注入是在配置文件里完成的(Spring dm提供了引用的annotation方式引入,但是不推荐使用),所以这里照常的Autowired就可以了。
(3)spring配置
(3.1)osgi-context.xml
<?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" xmlns:context="http://www.springframework.org/schema/context" 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 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <osgi:reference id="contactDao" interface="net.georgezeng.test.dao.ContactDao" /> <osgi:reference id="transactionManager" interface="org.springframework.transaction.PlatformTransactionManager" /> <osgi:service ref="ContactService" interface="net.georgezeng.test.service.ContactService" ></osgi:service> </beans>
这里声明了需要的OSGI服务的引用,我们看到上一节中定义的transactionManager也在这个地方被用到了,因为事务的入口通常就是在service里开始的。
然后这里还曝露了1个ContactService的服务,让web bundle可以使用到这个服务。
(3.2)appContext.xml
<?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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:annotation-config /> <context:component-scan base-package="net.georgezeng.test" /> <tx:annotation-driven transaction-manager="transactionManager" /> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="find*" read-only="true" /> <tx:method name="*" rollback-for="Exception" /> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id="serviceCut" expression="execution(* net.georgezeng.test..service..*.*(..))" /> <aop:advisor pointcut-ref="serviceCut" advice-ref="txAdvice" /> </aop:config> </beans>
使用了annotation的方式来管理事务,所以定义了下面这个内容:
<tx:annotation-driven transaction-manager="transactionManager" />
虽然我们定义了使用annotation作为事务管理的方式,但是我们可以为整个事务定义一个默认的切面,用来处理默认的事务管理,比如哪些方法只读,或者遇到什么异常回滚等。所以上面定义了一个aop:config和txadvice来做这个事情,并将我们的transactionManager注入。
(4)MANIFEST.MF
(4.1)import
(4.2)export
没有需要export的内容
至此Service Interface Bundle 和 Service Implementation Bundle就开发完成了
附上源码
- net.georgezeng.test.service.zip (11.2 KB)
- 下载次数: 185
- net.georgezeng.test.service.impl.zip (15.5 KB)
- 下载次数: 179
发表评论
-
手把手教会你开发动态web项目(4)
2016-03-12 10:50 646本文将会讲解如何使用IntelliJ来进行debug ... -
手把手教会你开发动态web项目(3)
2016-03-12 10:23 591本章讲述如何进行业务 ... -
手把手教会你开发动态web项目(2)
2016-03-12 09:45 548这一章主要讲项目的结构。 1. 项目使用gradle进行管 ... -
手把手教会你开发动态web项目(1)
2016-03-11 16:34 892框架终于搭建得差不多了,现在分享一下如何利用此框架进行动态 ... -
基于virgo环境的OSGI+Maven的web开发代码下载(spring+hibernate+GWT)
2012-05-16 20:54 8901由于很多朋友在使用我的上一个版本的web开发遇到了非常多的问题 ... -
关于新版本的STS安装新virgo插件的问题
2012-02-28 21:30 6922新的sts已经没有spring dm server tool的 ... -
virgo server使用指南(2)
2011-10-22 15:47 6324这个章节来看看virgo server的目录结构,如有错漏请 ... -
virgo server使用指南(1)
2011-08-27 10:23 9709virgo server的前身是spring dm serve ... -
OSGI下的web应用开发(7)
2011-07-23 12:52 7161现在我们要进入最后一 ... -
OSGI下的web应用开发(5)
2011-07-22 19:04 7638这一节将对Dao Interface Bundle 和 D ... -
OSGI下的web应用开发(4)
2011-07-22 17:28 3740接下来开发Domain Bundle这个模块。这个Bundle ... -
OSGI下的web应用开发(3)
2011-07-21 18:10 6826上节讲了如何对web应用 ... -
OSGI下的web应用开发(2)
2011-07-21 13:28 5270前面已经讲了开发环境 ... -
OSGI下的web应用开发(1)
2011-07-20 21:33 10026本文将详细的展示OSGI下如何开发一个基于spring的web ... -
OSGI心得体会
2011-07-14 16:13 15052l 什么是模块化 与 ... -
OSGI知识小计(3)- bundle的总结
2011-04-26 20:37 59(1)bundle的identifier 在 ... -
OSGI知识小计(2)
2011-04-24 17:15 32(1)OSGI framework的类搜索顺序: 如 ... -
OSGI知识小计(1)
2011-04-22 21:03 71今天学习了OSGI的一些入 ... -
如何安装OSGI的模块(How to install bundle into OSGI Container)
2011-04-20 00:16 64今天开始学习OSGI的知识 ...
相关推荐
基于OSGi的Web应用开发系列(全).pdf基于OSGi的Web应用开发系列(全).pdf基于OSGi的Web应用开发系列(全).pdf基于OSGi的Web应用开发系列(全).pdf基于OSGi的Web应用开发系列(全).pdf基于OSGi的Web应用开发系列(全).pdf...
基于OSGi和Spring开发Web应用
基于OSGi和Spring开发Web应用
基于OSGi和Spring开发Web应用的博文对应的代码
行业分类-设备装置-基于OSGi的Web应用开发平台权限管理自适应设计方法.zip
基于OSGi和Spring开发Web应用教程 教程
开发一个简单的 OSGi Web 应用实例,如何进行OSGI开发的 实例有利于入门着进行使用
基于 OSGi 和 Spring 开发 Web 应用
1、自己开发的OSGi Web Console,适用于实现了OSGi规范的Equinox、Felix等...2、展示了如何把OSGi框架作为一个组件嵌入到现有的未基于OSGi开发的Web应用当中,在Web应用中可获取OSGi中的Service以增加应用的灵活性。
基于OSGi和Spring开发企业级Web应 目前OSGi和Spring已经受到了广泛的关注,如果我们将OSGi和Spring结合,更能充分发挥二者各自的特长,同时更好地满足企业级应用开发的需求。
我转载的博客“OSGi环境下建立Web工程的Hello World ”中列出的jar,结合博客“OSGi环境下建立Web工程的Hello World ”开发应用。
Spring DM 1.1.x最大特性便是它可以支持在其中部署WEB应用我使用后感觉这是个很酷特性我甚 至觉得用这种方式开发基于OSGi WEB...使用Spring DM进行WEB应用开发人来说成功地配置却不是件容易事,文档详细讲解了相关配置
辛苦研究了一个多月,终于搭建成了一个可用于实际应用开发的OSGI-WEB框架,采用OSGi+SpringMVC+Spring+Hibernate+Virgo技术,鉴于此类技术架构甚少,特提供出来供大家参考。 使用步骤: 一、下载STS搭建Osgi开发...
包括OSGI的相关书籍及网页: OSGi R4服务平台核心规范中译本 Spring OSGI入门 modular java OSGI原理与最佳实践 ...基于 OSGi 和 Spring 开发 Web 应用 基于 OSGi 的面向服务的组件编程 探索 OSGi 框架的组件运行机制
是一本适合新接触OSGI开发学习的一本很好的书,本书介绍了Equinox, Spring-DM和Felix这三个常用的OSGi容器的使用、开发、以及WebApplication的开发部署;介绍了OSGi的规范和Core Framework和Layer。包含书中的用例源...