1. 程式人生 > >OSGI企業應用開發(九)整合Spring和Mybatis框架(二)

OSGI企業應用開發(九)整合Spring和Mybatis框架(二)

上篇文章中,我們完成了在OSGI應用中整合Spring和Mybatis框架的準備工作,本節我們繼續Spring和Mybatis框架的整合。

一、解決OSGI整合Spring中的Placeholder問題

使用Spring框架的朋友應該都知道,我們可以在Bean的配置檔案中,使用${key}的形式訪問properties檔案中對應的value值,需要用到Spring中的PropertyPlaceholderConfigurer類,使用方式如下,首先需要配置placeholder,例如:

<bean id="placeholder"class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
>
<property name="location"> <value>conf/jdbc.properties</value> </property> </bean>

conf/jdbc.properties檔案內容如下:

jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost/mysqldb?useUnicode=true&amp;characterEncoding=UTF-8&amp;
jdbc.username
=root jdbc.password=123456

然後我們定義Bean的時候,就可以使用${key}的方式訪問jdbc.properties檔案中的內容,例如:

<bean id="dataSource"class="org.apache.commons.dbcp.BasicDataSource"destroy-method="close">
  <property name="driverClassName"value="${jdbc.driverClassName}" />
  <property name="url" value="${jdbc.url}"
/> <property name="username" value="${jdbc.username}"/> <property name="password"value="${jdbc.password}" /> </bean>

但是在OSGI應用中,並沒有全域性的Classpath的概念,其中一個Bundle的屬性檔案在其他Bundle中無法訪問,而且不同Bundle中的ApplictionContext也是獨立的,PropertyPlaceholderConfigurer例項在不同的Bundle中不是共享的,所以Spring框架中的Placeholder配置也就存在一定的問題。

Gemini Blueprint為OSGI應用中使用Placeholder提供了一種解決方案,但是基於Key-Value的配置資訊需要定義在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:osgix="http://www.springframework.org/schema/osgi-compendium"
   xmlns:ctx="http://www.springframework.org/schema/context"
   xmlns:osgi="http://www.eclipse.org/gemini/blueprint/schema/blueprint"
   xsi:schemaLocation="
    http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context 
      http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/osgi-compendium 
      http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd
      http://www.eclipse.org/gemini/blueprint/schema/blueprint 
       http://www.eclipse.org/gemini/blueprint/schema/blueprint/gemini-blueprint.xsd">

   <osgix:cm-properties id="dbInfo" persistent-id="com.csdn.osgi.common">
      <prop key="driver">com.mysql.jdbc.Driver</prop>
      <prop key="url">jdbc:mysql://127.0.0.1:3306/osgi</prop>
      <prop key="username">root</prop>
      <prop key="password"></prop>
   </osgix:cm-properties>

   <ctx:property-placeholder properties-ref="dbInfo" />

</beans>

接下來在Bean的定義中,就可以一${Key}的形式訪問Value值了,例如:

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">         
        <property name="driverClassName" value="${driver}" />  
        <property name="url" value="${url}" />  
        <property name="username" value="${username}" />     
        <property name="password" value="${password}" />        
    </bean>

二、Spring與Mybatis框架整合

1、首先新建一個Plug-in Project,名稱為com.csdn.osgi.database,該Bundle用於操作資料庫。

2、接著在com.csdn.osgi.database工程中新建META-INF/spring目錄,然後在該目錄下新建database.xml檔案,用於配置資料來源及Mybatis-Spring外掛提供的SqlSessionFactoryBean和SqlSessionTemplate的例項,以及事務管理器等。
database.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">


    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">         
        <property name="driverClassName" value="${driver}" />  
        <property name="url" value="${url}" />  
        <property name="username" value="${username}" />     
        <property name="password" value="${password}" />        
    </bean>   

    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> 
      <property name="dataSource" ref="dataSource" /> 
      <property name="configLocation" value="classpath:sqlMap.xml"/>
    </bean>

    <!-- 建立SqlSessionTemplate -->
    <bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate"> 
      <constructor-arg index="0" ref="sqlSessionFactory" /> 
    </bean>

    <!-- 事務管理 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">  
        <property name="dataSource" ref="dataSource" />  
    </bean> 

    <!--事務模板 -->  
    <bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate">  
        <property name="transactionManager">  
            <ref local="transactionManager" />  
        </property>  
        <!--ISOLATION_DEFAULT 表示由使用的資料庫決定  -->  
        <property name="isolationLevelName" value="ISOLATION_DEFAULT"/>  
        <property name="propagationBehaviorName" value="PROPAGATION_REQUIRED"/>
    </bean>  
</beans>

3、接下來在META-INF/spring目錄下,新建一個dmconfig.xml檔案,用於配置placeholder及註冊sqlSessionTemplate這個Bean,這樣在其他Bundle中就可以通過引用我們註冊的sqlSessionTemplate來操作資料庫了。
dmconfig.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:osgix="http://www.springframework.org/schema/osgi-compendium"
   xmlns:ctx="http://www.springframework.org/schema/context"
   xmlns:osgi="http://www.eclipse.org/gemini/blueprint/schema/blueprint"
   xsi:schemaLocation="
    http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context 
      http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/osgi-compendium 
      http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd
      http://www.eclipse.org/gemini/blueprint/schema/blueprint 
       http://www.eclipse.org/gemini/blueprint/schema/blueprint/gemini-blueprint.xsd">

   <osgix:cm-properties id="dbInfo" persistent-id="com.csdn.osgi.common">
      <prop key="driver">com.mysql.jdbc.Driver</prop>
      <prop key="url">jdbc:mysql://127.0.0.1:3306/osgi</prop>
      <prop key="username">root</prop>
      <prop key="password"></prop>
   </osgix:cm-properties>

   <ctx:property-placeholder properties-ref="dbInfo" />

   <osgi:service id="sqlMapService" ref="sqlSessionTemplate" interface="org.apache.ibatis.session.SqlSession" />
</beans>

4、接下來就是Mybatis主配置檔案和SQL的配置了,在sqlSessionFactory這個Bean的配置中,我們指定了Mybatis配置檔案為sqlMap.xml,如下:

    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> 
      <property name="dataSource" ref="dataSource" /> 
      <property name="configLocation" value="classpath:sqlMap.xml"/>
    </bean>

所以需要在com.csdn.osgi.database工程的src目錄下新建一個sqlMap.xml檔案,內容如下:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
    PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
    "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <mappers>
        <mapper resource="user.xml"/>
    </mappers>
</configuration>

上面配置中,我們指定了SQL配置檔案為user.xml,接著在com.csdn.osgi.database工程的src目錄下新建user.xml檔案,內容如下:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="user">
    <insert id="saveUser" parameterType="java.util.HashMap">
        insert into user(username,password) values(#{UserName},#{Password});
    </insert>

    <select id="getPasswordByName" parameterType="java.lang.String" resultType="java.lang.String">
        select password from user where username = #{UserName}
    </select>
</mapper>

5、整個工程目錄及檔案結構如下圖所示:
這裡寫圖片描述
6、然後還需要對com.csdn.osgi.database工程的MANIFEST.MF檔案新建修改,新增如下Bundle的依賴:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Database
Bundle-SymbolicName: com.csdn.osgi.database
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: CSDN
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.springframework.jdbc;bundle-version="3.0.0",
 org.mybatis.mybatis;bundle-version="3.1.1",
 com.springsource.org.apache.commons.dbcp;bundle-version="1.2.2",
 com.springsource.org.apache.commons.pool;bundle-version="1.3.0",
 org.springframework.transaction;bundle-version="3.0.0",
 com.springsource.com.mysql.jdbc;bundle-version="5.1.6",
 org.mybatis.mybatis-spring;bundle-version="1.2.3"

上面MANIFEST.MF檔案中,Require-Bundle元資料頭為新增。

7、最後一步,啟動OSGI容器。需要單擊Run=>Debug Configurations…選單,如下圖所示:
這裡寫圖片描述

單擊Validate Bundles按鈕,檢視是否存在Bundle依賴問題,筆者單擊後如下圖所示:
這裡寫圖片描述

說明存在依賴問題,解決方法非常簡單,單擊面板上的Add Required Bundles按鈕即可。

啟動後輸出控制檯輸出日誌內容如下:

一月 07, 2017 3:40:33 下午 org.eclipse.gemini.blueprint.extender.internal.boot.ChainActivator <init>
資訊: Blueprint API detected; enabling Blueprint Container functionality
一月 07, 2017 3:40:33 下午 org.eclipse.gemini.blueprint.extender.internal.activator.LoggingActivator start
資訊: Starting [org.eclipse.gemini.blueprint.extender] bundle v.[2.0.0.M02]
osgi> 一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.extender.internal.support.ExtenderConfiguration start
資訊: No custom extender configuration detected; using defaults...
一月 07, 2017 3:40:34 下午 org.springframework.scheduling.timer.TimerTaskExecutor afterPropertiesSet
資訊: Initializing Timer
hello world!
一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.extender.support.DefaultOsgiApplicationContextCreator createApplicationContext
資訊: Discovered configurations {osgibundle:/META-INF/spring/*.xml} in bundle [Common (com.csdn.osgi.common)]
Hello World!!
一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.extender.support.DefaultOsgiApplicationContextCreator createApplicationContext
資訊: Discovered configurations {config/*.xml} in bundle [Helloworld (com.csdn.osgi.helloworld)]
一月 07, 2017 3:40:34 下午 org.springframework.context.support.AbstractApplicationContext prepareRefresh
資訊: Refreshing OsgiBundleXmlApplicationContext(bundle=com.csdn.osgi.common, config=osgibundle:/META-INF/spring/*.xml): startup date [Sat Jan 07 15:40:34 CST 2017]; root of context hierarchy
一月 07, 2017 3:40:34 下午 org.springframework.context.support.AbstractApplicationContext prepareRefresh
資訊: Refreshing OsgiBundleXmlApplicationContext(bundle=com.csdn.osgi.helloworld, config=config/*.xml): startup date [Sat Jan 07 15:40:34 CST 2017]; root of context hierarchy
一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.context.support.AbstractOsgiBundleApplicationContext unpublishContextAsOsgiService
資訊: Application Context service already unpublished
一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.extender.internal.blueprint.activator.support.BlueprintContainerCreator createApplicationContext
資訊: Discovered configurations {bundleentry://43.fwk2082351774/OSGI-INF/blueprint/beans.xml} in bundle [Helloworld (com.csdn.osgi.helloworld)]
一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.context.support.AbstractOsgiBundleApplicationContext unpublishContextAsOsgiService
資訊: Application Context service already unpublished
一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.extender.support.DefaultOsgiApplicationContextCreator createApplicationContext
資訊: Discovered configurations {osgibundle:/META-INF/spring/*.xml} in bundle [Database (com.csdn.osgi.database)]
一月 07, 2017 3:40:34 下午 org.springframework.context.support.AbstractApplicationContext prepareRefresh
資訊: Refreshing OsgiBundleXmlApplicationContext(bundle=com.csdn.osgi.database, config=osgibundle:/META-INF/spring/*.xml): startup date [Sat Jan 07 15:40:34 CST 2017]; root of context hierarchy
一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.context.support.AbstractOsgiBundleApplicationContext unpublishContextAsOsgiService
資訊: Application Context service already unpublished
一月 07, 2017 3:40:34 下午 org.springframework.context.support.AbstractApplicationContext prepareRefresh
資訊: Refreshing OsgiBundleXmlApplicationContext(bundle=com.csdn.osgi.helloworld, config=bundleentry://43.fwk2082351774/OSGI-INF/blueprint/beans.xml): startup date [Sat Jan 07 15:40:34 CST 2017]; root of context hierarchy
一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.context.support.AbstractOsgiBundleApplicationContext unpublishContextAsOsgiService
資訊: Application Context service already unpublished
一月 07, 2017 3:40:34 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
資訊: Loading XML bean definitions from OSGi resource[bundleentry://43.fwk2082351774/OSGI-INF/blueprint/beans.xml|bnd.id=43|bnd.sym=com.csdn.osgi.helloworld]
一月 07, 2017 3:40:34 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
資訊: Loading XML bean definitions from URL [bundleentry://37.fwk2082351774/META-INF/spring/beans.xml]
一月 07, 2017 3:40:34 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
資訊: Loading XML bean definitions from URL [bundleentry://46.fwk2082351774/META-INF/spring/database.xml]
一月 07, 2017 3:40:34 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
資訊: Loading XML bean definitions from URL [bundleentry://43.fwk2082351774/config/beans.xml]
一月 07, 2017 3:40:34 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
資訊: Loading XML bean definitions from URL [bundleentry://43.fwk2082351774/config/company.xml]
一月 07, 2017 3:40:34 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
資訊: Loading XML bean definitions from URL [bundleentry://46.fwk2082351774/META-INF/spring/dmconfig.xml]
一月 07, 2017 3:40:34 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
資訊: Loading XML bean definitions from URL [bundleentry://37.fwk2082351774/META-INF/spring/dmconfig.xml]
一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor stageOne
資訊: No outstanding OSGi service dependencies, completing initialization for OsgiBundleXmlApplicationContext(bundle=com.csdn.osgi.helloworld, config=bundleentry://43.fwk2082351774/OSGI-INF/blueprint/beans.xml)
一月 07, 2017 3:40:34 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
資訊: Loading XML bean definitions from URL [bundleentry://43.fwk2082351774/config/dmconfig.xml]
================Hello World================
一月 07, 2017 3:40:34 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
資訊: Loading XML bean definitions from URL [bundleentry://37.fwk2082351774/META-INF/spring/employee.xml]
一月 07, 2017 3:40:34 下午 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
資訊: Pre-instantiating singletons in org.s[email protected]215dd7af: defining beans [helloWorld,blueprintBundle,blueprintBundleContext,blueprintContainer,blueprintConverter]; root of factory hierarchy
一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor stageOne
資訊: No outstanding OSGi service dependencies, completing initialization for OsgiBundleXmlApplicationContext(bundle=com.csdn.osgi.common, config=osgibundle:/META-INF/spring/*.xml)
一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.blueprint.container.support.BlueprintContainerServicePublisher registerService
資訊: Publishing BlueprintContainer as OSGi service with properties {Bundle-SymbolicName=com.csdn.osgi.helloworld, Bundle-Version=1.0.0.qualifier, osgi.blueprint.container.version=1.0.0.qualifier, osgi.blueprint.container.symbolicname=com.csdn.osgi.helloworld}
一月 07, 2017 3:40:34 下午 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
資訊: Pre-instantiating singletons in org.s[email protected]68bf15f1: defining beans [object,length,buffer,current-time,list,employee,programmer]; root of factory hierarchy
一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.context.support.AbstractOsgiBundleApplicationContext publishContextAsOsgiServiceIfNecessary
資訊: Publishing application context as OSGi service with properties {org.eclipse.gemini.blueprint.context.service.name=com.csdn.osgi.helloworld, org.springframework.context.service.name=com.csdn.osgi.helloworld, Bundle-SymbolicName=com.csdn.osgi.helloworld, Bundle-Version=1.0.0.qualifier}
一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.extender.internal.dependencies.startup.DependencyServiceManager doFindDependencies
資訊: Adding OSGi service dependency for importer [&employee] matching OSGi filter [(objectClass=com.csdn.osgi.domain.Employee)]
一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.extender.internal.support.DefaultOsgiBundleApplicationContextListener onOsgiApplicationEvent
資訊: Application context successfully refreshed (OsgiBundleXmlApplicationContext(bundle=com.csdn.osgi.helloworld, config=bundleentry://43.fwk2082351774/OSGI-INF/blueprint/beans.xml))
一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.extender.internal.dependencies.startup.DependencyServiceManager findServiceDependencies
資訊: OsgiBundleXmlApplicationContext(bundle=com.csdn.osgi.helloworld, config=config/*.xml) is waiting for unsatisfied dependencies [[&employee]]
一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor stageOne
資訊: No outstanding OSGi service dependencies, completing initialization for OsgiBundleXmlApplicationContext(bundle=com.csdn.osgi.database, config=osgibundle:/META-INF/spring/*.xml)
一月 07, 2017 3:40:34 下午 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
資訊: Pre-instantiating singletons in org.s[email protected]30d1126b: defining beans [dataSource,sqlSessionFactory,sqlSessionTemplate,transactionManager,transactionTemplate,dbInfo,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,sqlMapService]; root of factory hierarchy
一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.service.exporter.support.OsgiServiceFactoryBean registerService
資訊: Publishing service under classes [{com.csdn.osgi.domain.Employee}]
一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.extender.internal.dependencies.startup.DependencyServiceManager$DependencyServiceListener serviceChanged
資訊: No unsatisfied OSGi service dependencies; completing initialization for OsgiBundleXmlApplicationContext(bundle=com.csdn.osgi.helloworld, config=config/*.xml)
一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.context.support.AbstractOsgiBundleApplicationContext publishContextAsOsgiServiceIfNecessary
資訊: Publishing application context as OSGi service with properties {org.eclipse.gemini.blueprint.context.service.name=com.csdn.osgi.common, org.springframework.context.service.name=com.csdn.osgi.common, Bundle-SymbolicName=com.csdn.osgi.common, Bundle-Version=1.0.0.qualifier}
一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.extender.internal.support.DefaultOsgiBundleApplicationContextListener onOsgiApplicationEvent
資訊: Application context successfully refreshed (OsgiBundleXmlApplicationContext(bundle=com.csdn.osgi.common, config=osgibundle:/META-INF/spring/*.xml))
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
一月 07, 2017 3:40:34 下午 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
資訊: Pre-instantiating singletons in org.s[email protected]4f805c92: defining beans [helloWorld1,helloWorld2,company,employee]; root of factory hierarchy
================Hello World================
================Hello World================
=========Company=========
一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.context.support.AbstractOsgiBundleApplicationContext publishContextAsOsgiServiceIfNecessary
資訊: Publishing application context as OSGi service with properties {org.eclipse.gemini.blueprint.context.service.name=com.csdn.osgi.helloworld, org.springframework.context.service.name=com.csdn.osgi.helloworld, Bundle-SymbolicName=com.csdn.osgi.helloworld, Bundle-Version=1.0.0.qualifier}
一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.extender.internal.support.DefaultOsgiBundleApplicationContextListener onOsgiApplicationEvent
資訊: Application context successfully refreshed (OsgiBundleXmlApplicationContext(bundle=com.csdn.osgi.helloworld, config=config/*.xml))
一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.service.exporter.support.OsgiServiceFactoryBean registerService
資訊: Publishing service under classes [{org.apache.ibatis.session.SqlSession}]
一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.context.support.AbstractOsgiBundleApplicationContext publishContextAsOsgiServiceIfNecessary
資訊: Publishing application context as OSGi service with properties {org.eclipse.gemini.blueprint.context.service.name=com.csdn.osgi.database, org.springframework.context.service.name=com.csdn.osgi.database, Bundle-SymbolicName=com.csdn.osgi.database, Bundle-Version=1.0.0.qualifier}
一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.extender.internal.support.DefaultOsgiBundleApplicationContextListener onOsgiApplicationEvent
資訊: Application context successfully refreshed (OsgiBundleXmlApplicationContext(bundle=com.csdn.osgi.database, config=osgibundle:/META-INF/spring/*.xml))

從日誌檔案中可以分析出,Mybatis相關的Bean已經例項化成功,本節內容先介紹這麼多,下篇檔案中我們在其他Bundle中通過Mybatis-Spring外掛提供的模版類操作資料庫。

注意:上篇文章提到使用Mybatis-Spring外掛版本為1.2.0,與Spring 3.0整合存在一定的問題,本文中筆者將Mybatis-Spring外掛版本改為1.2.3。

相關推薦

OSGI企業應用開發整合SpringMybatis框架

上篇文章中,我們完成了在OSGI應用中整合Spring和Mybatis框架的準備工作,本節我們繼續Spring和Mybatis框架的整合。 一、解決OSGI整合Spring中的Placeholder問題 使用Spring框架的朋友應該都知道,我們可以在B

JavaWeb開發基於Springmybatis框架學習日誌

我更想把它當成我的日誌: 今天是迴歸javaweb的第一天…… 先說一下我對spring框架的理解(個人意見):從控制器捕獲了url然後用方法執行某個jsp,如果需要執行特殊的操作,例如將資料庫裡的資料展示在jsp頁面中,就需要在控制器方法中呼叫

OSGI企業應用開發Eclipse中搭建Felix執行環境

上篇文章介紹了什麼是OSGI以及使用OSGI構建應用的優點,接著介紹了兩款常用的OSGI實現,分別為Apache Felix和Equinox,接下來開始介紹如何在Eclipse中使用Apache Felix和Equinox搭建OSGI執行環境。 一、搭建A

OSGI企業應用開發十五基於SpringMybatisSpring MVC實現一個登入應用

前面文章中,我們已經完成了OSGI應用中Spring、Mybatis、Spring MVC的整合,本篇文章我們就在這個基礎上來完成一個簡單的登入應用,其中使用者名稱和密碼需要從資料庫中查詢。 前面文章中,我們已經搭建好的工作空間如下圖所示: 本篇文章中,

使用idea搭建Maven+SSM(Spring+SpringMVC+Mybatis)框架一、使用Maven創建新工程

post eight 9.png 圖片 tis 本地包 end pen nbsp 一、新建Maven項目 1、如圖創建簡單java web application。 2、如圖填寫組織唯一標識和項目唯一標識 3、如圖照做 4、點擊finish即可完成項目創建,如圖為創建

整合springmybatis

spring-mybatis-druid:整合spring和mybatis,使用阿里公司的druid資料庫的連線池&以下是apache基金會的dbcp連線池 <bean id="myDataSource" class="org.apache.commons.dbcp2

整合springmybatis時,異常java.lang.AbstractMethodError: org.mybatis.spring.transaction.SpringManagedTrans

觸發原因:單方面升級mybatis版本。 mybatis、mybatis-spring版本如下: <dependency> <groupId>org.mybatis</groupId> <artifa

IDEA下Maven專案整合SpringMyBatis出現jdbc.properties is invalid;前言中不允許有內容

在Idea下用Maven管理Spring和MyBatis整合的專案,在Junit測試service層程式碼時不會出錯,但把整個專案釋出到Tomcat時丟擲各種各樣的異常,花了最多時間的異常為: o

Spring 入門例項 簡易登入系統精通Spring+4.x++企業應用開發實戰 學習筆記一

論壇登入模組 在持久層有兩個DAO類,分別是UserDao和LoginLogDao,在業務層對應一個業務類UserService,在展現層擁有一個LoginController類和兩個JSP頁面,分別是登入頁面login.jsp和登入成功頁面main.js

Spring.NET教程整合NHibernateASP.NET MVC(基礎篇)

contains sar occurs false port company param soft stat 今天帶給大家的就是期待以久的ASP.net MVC與Spring.NET和NHibernate的組合,視圖打造.NET版的SSH(Spring-Struts-Hib

Java架構-整合spring cloud雲服務架構 - 企業分散式微服務雲架構構建

今天正式給大家介紹了Spring Cloud - 企業分散式微服務雲架構構建,我這邊結合了當前大部分企業的通用需求,包括技術的選型比較嚴格、苛刻,不僅要用業界最流行的技術,還要和國際接軌,在未來的5~10年內不能out。作為公司的架構師,也要有一種放眼世界的眼光,不僅要給公司做好的技術選

Java架構-整合spring cloud雲服務架構 - 企業雲架構common-service程式碼結構分析

當前的分散式微服務雲架構平臺使用Maven構建,所以common-service的通用服務按照maven構建獨立的系統服務,結構如下: particle-commonservice: spring cloud 系統服務根專案,所有服務專案的根依賴。 particle-commo

整合spring cloud雲服務架構 - 企業分布式微服務雲架構構建

企業項目 ges img 部分 ado 技術分享 tex 圖片 proc 今天正式給大家介紹了Spring Cloud - 企業分布式微服務雲架構構建,我這邊結合了當前大部分企業的通用需求,包括技術的選型比較嚴格、苛刻,不僅要用業界最流行的技術,還要和國際接軌,在未來的5~

整合spring cloud雲服務架構 - 企業雲架構common-service代碼結構分析

註冊 基於 桌面應用 web 支持 系統 第三方 rabbit red 當前的分布式微服務雲架構平臺使用Maven構建,所以common-service的通用服務按照maven構建獨立的系統服務,結構如下: particle-commonservice: spring cl

Android開發:app工程整合銀聯支付功能伺服器端

2016年5月6日有更新,請參考第三部分。 一.功能描述 因為是自己開發了一個app應用,沒資格去申請微信支付和支付寶支付,於是就採用了銀聯支付功能,銀聯支付分為了兩種環境:測試環境和生產環境,一般前期開發的時候都是使用測試環境,資料都是測試資料,

整合spring cloud雲服務架構 - particle雲架構

介紹 能夠 步驟 架構 第一篇 img .net 業務 服務架構 第一篇文章簡單給大家介紹了Spring Cloud架構,我這邊結合了當前大部分企業的通用需求,包括技術的選型比較嚴格、苛刻,不僅要用業界最流行的技術,還要和國際接軌,在未來的5~10年內不能out。作為公司

整合spring cloud雲服務架構 - Spring Cloud簡介

springcloud 架構 雲服務 Spring Cloud是一系列框架的有序集合。利用Spring Boot的開發模式簡化了分布式系統基礎設施的開發,如服務發現、註冊、配置中心、消息總線、負載均衡、斷路器、數據監控等(這裏只簡單的列了一部分),都可以用Spring Boot的開發風格做到一鍵啟動和部署

整合spring cloud雲服務架構 - particle雲架構代碼結構構建

itl log lan 作用 購物 基本架構 集成 eight control 上一篇介紹了spring cloud雲服務架構的基本架構圖,本篇我們根據架構圖進行代碼的構建,根據微服務化設計思想,結合spring cloud本身的服務發現、治理、配置化管理、分布式等項目優秀

整合spring cloud雲服務架構 - particle-common-framework代碼介紹

.cn server control 簡單的 阿裏巴巴 統計 icontrol htm 回顧 上一篇我們介紹了spring cloud雲服務架構 - particle雲架構代碼結構,簡單的按照幾個大的部分去構建代碼模塊,讓我們來回顧一下: 第一部分: 針對於普通服務的基礎

整合spring cloud雲服務架構 - HongHu雲架構common-service代碼結構分析

如何 通過 -m 交互 art 實現 使用 sof 組織 當前的分布式微服務雲架構平臺使用Maven構建,所以common-service的通用服務按照maven構建獨立的系統服務,結構如下: particle-commonservice: spring cloud 系統