`
mizhao1984
  • 浏览: 88517 次
  • 性别: Icon_minigender_1
  • 来自: 西安
社区版块
存档分类
最新评论

osgi配置数据源bundle供其他bundle使用

阅读更多

1.创建plug-in project:

此bundle依赖jar包:

commons-dbcp-1.2.2.jar
commons-pool-1.3.jar
oracle-jdbc-10g.jar
spring-beans-2.5.6.jar
spring-dao-2.5.6.jar
spring-jdbc-2.5.6.jar

在META-INF下新建spring文件夹,并在文件夹里创建jdbc.xml,services-publish-cxf.xml

jdbc.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"
 xsi:schemaLocation="http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans.xsd"
 default-autowire="byName">
 <!-- datasource -->
 <bean id="_dataSource"  class="com.thewebpagestudio.util.jdbc.BasicDataSource">
  <constructor-arg index="0"
   value="oracle.jdbc.driver.OracleDriver"></constructor-arg>
  <constructor-arg index="1"
   value="jdbc:oracle:thin:@192.168.0.57:1521:xe"></constructor-arg>
  <constructor-arg index="2" value="surfing_campus"></constructor-arg>
  <constructor-arg index="3" value="20100504"></constructor-arg>
 </bean>
</beans>

 

services-publish-cxf.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"
  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:service id="dataSource" ref="_dataSource" interface="javax.sql.DataSource"></osgi:service>
</beans>

 

2。创建测试数据源的bundle:

bundle依赖包:

spring-beans-2.5.6.jar
spring-dao-2.5.6.jar
spring-jdbc-2.5.6.jar

新建测试类:

package com.oohla.test;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.jdbc.core.JdbcTemplate;

public class TestDataSource {
 
 public static final Log log = LogFactory.getLog(TestDataSource.class);

 private JdbcTemplate jdbcTemplate;

    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }
 
 public void init() throws Exception{
  int count = jdbcTemplate.queryForInt("select count(*) from sms_log");
  log.info("count2222222222222222222222222" + count);
 }

}

 

在META-INF下新建spring文件夹,并在文件夹里创建beans.xml,services-reference-cxf.xml

beans.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"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans.xsd" default-autowire="byName">
        
      <!-- 启动通话监听任务 -->
      <bean class="com.oohla.test.TestDataSource" init-method="init"></bean>
   
      <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"/>
</beans>

 

<?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" default-autowire="byName">
   
    <osgi:reference id="dataSource" interface="javax.sql.DataSource" />                  
   
</beans>

 

注:如果运行过程中报:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.oohla.test.TestDataSource#0' defined in URL [bundleentry://155.fwk7031149/META-INF/spring/beans.xml]: Invocation of init method failed; nested exception is org.springframework.aop.AopInvocationException: AOP configuration seems to be invalid: tried calling method [public abstract java.sql.Connection javax.sql.DataSource.getConnection() throws java.sql.SQLException] on target [com.thewebpagestudio.util.jdbc.BasicDataSource@c932df]; nested exception is java.lang.IllegalArgumentException: object is not an instance of declaring class 错误

这是由于 osgi加载机制的原因

 

解决方法:在jvm设置中添加-Dorg.osgi.framework.bootdelegation=*

分享到:
评论

相关推荐

    OSGi with CAR-Bundle

    OSGi with CAR-Bundle.ppt

    osgi多个bundle读取同一配置文件

    osgi多个bundle之间读取同一配置文件,需要单独添加一个用来读取配置文件的bundle

    OSGI bundle

    OSGI bundle 在线用户管理 邮件发送

    osgi发布http服务的各种bundle,各种jar包,全全全~

    osgi发布http服务的各种bundle,各种jar包,全全全~非常好用的技术包 包括:org.eclipse.equinox.http_1.0.0.v20060601a.jar org.eclipse.equinox.ds_1.0.0.v20060601a.jar org.eclipse.equinox.servlet.api_1.0.0...

    浅析OSGI的bundle依赖

    NULL 博文链接:https://salever.iteye.com/blog/1474694

    OSGi进阶源代码

    OSGi进阶源代码,OSGi集成webwork + spring + hibernate

    osgi数据库连接demo

    osgi数据库连接一章demo,c3p0配置oracle连接池和ibatis在osgi框架中的使用

    osgi 3.7.1 源代码

    工作中用到了osgi,又需要阅读或者修改osgi的源代码,好不容易找到了3.71版的,其实我需要的只是org.eclipse.osgi.source_3.7.1.R37x_v20110808-1106.jar,里面有osgi类加载相关的代码,它位于压缩包的equinox-SDK-...

    基于EQUINOX的 OSGI BUNDLE 运行例子

    基于 equinox 的 OSGI 运行BUNDLE例子,已包含 ECLIPSE 下的OSGI平台包,按步骤运行即可。 当然,设置JAVA_HOME,及BIN环境变量运行JAVAC 就不用说了 ^-^

    blueprint-osgi-bundle:OSGi 示例

    blueprint-osgi-bundle

    osgi介绍osgi介绍

    osgi介绍osgi介绍osgi介绍osgi介绍osgi介绍osgi介绍osgi介绍osgi介绍osgi介绍osgi介绍

    OSGi+SpringMVC+Spring+Hibernate企业应用框架

    辛苦研究了一个多月,终于搭建成了一个可用于实际应用开发的OSGI-WEB框架,采用OSGi+SpringMVC+Spring+Hibernate+Virgo技术,鉴于此类技术架构甚少,特提供出来供大家参考。 使用步骤: 一、下载STS搭建Osgi开发...

    OSGI原理最佳实践(包含源代码)

    包含书中的用例源代码供大家研究学习。 OSGi国内推广者林昊多年经验的结晶 涵盖OSGi从入门到深入的知识体系 引领OSGi国内研究和普及 本书基于作者多年使用OSGi的经验而编写,涵盖了OSGi从入门到深入的知识体系,从...

    OSGi实战 实例源代码

    BlueDavy的opendoc《OSGi实战》所涉及实例的源代码。OSGi入门的经典教程。

    Equinox OSGI ServletBridge 原理与实践.rar

    本文将介绍 Equinox 的 ServletBridge 项目,提供一个示例来说明如何使用 ... 前一种:和普通的 OSGI bundle 开发差不多,而后一种:Equinox 提供 servletBridge 来将 OSGI framework 和 Servelet Container 联系起来。

    OSGi.NET框架 Documentation

    本文档主要针对OSGi.NET模块化框架使用进行了描述 OSGi.NET框架是一个参照了OSGi规范的模块化管理框架。框架为应用程序(组件(bundle))提供了一个标准环境。整个框架可以划分为一些层次: 1.运行环境 2.模块...

    OSGI bundle change listener

    NULL 博文链接:https://qtlkw.iteye.com/blog/2214254

    基于osgi整合ssm框架注解开发

    基于osgi整合ssm框架开发web项目,使用ssm注解的方式开发,缺少两个jsp文件,能运行

    《OSGi实战》完整中文版

    《 OSGi实战》是学习OSGi的全面指导,利用与架构和开发人员相关的示例清楚地讲解OSGi概念,同时探讨了很多实践场景和技术,阐述了开发人员有多需要OSGi,怎么将OSGi嵌入其他容器中,将遗留系统移入OSGi的最佳实践,...

    osgi-bundle-hello-world:使用Maven的演示OSGI捆绑包

    编译 mvn软件包将在目标中生成捆绑罐 跑步 将捆绑罐复制到OSGI容器,例如Felix或Faraf ...

Global site tag (gtag.js) - Google Analytics