上篇文章中,我们完成了在OSGI应用中整合Spring和Mybatis框架的准备工作,本节我们继续Spring和Mybatis框架的整合。

一、解决OSGI整合Spring中的Placeholder问题

使用Spring框架的朋友应该都知道,我们可以在Bean的配置文件中,使用${key}的形式访问properties文件中对应的value值,需要用到Spring中的PropertyPlaceholderConfigurer类,使用方式如下,首先需要配置placeholder,例如:

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

conf/jdbc.properties文件内容如下:

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

然后我们定义Bean的时候,就可以使用${key}的方式访问jdbc.properties文件中的内容,例如:

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

但是在OSGI应用中,并没有全局的Classpath的概念,其中一个Bundle的属性文件在其他Bundle中无法访问,而且不同Bundle中的ApplictionContext也是独立的,PropertyPlaceholderConfigurer实例在不同的Bundle中不是共享的,所以Spring框架中的Placeholder配置也就存在一定的问题。

Gemini Blueprint为OSGI应用中使用Placeholder提供了一种解决方案,但是基于Key-Value的配置信息需要定义在XML文件中,例如:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:osgix="http://www.springframework.org/schema/osgi-compendium"
  5. xmlns:ctx="http://www.springframework.org/schema/context"
  6. xmlns:osgi="http://www.eclipse.org/gemini/blueprint/schema/blueprint"
  7. xsi:schemaLocation="
  8. http://www.springframework.org/schema/beans
  9. http://www.springframework.org/schema/beans/spring-beans.xsd
  10. http://www.springframework.org/schema/context
  11. http://www.springframework.org/schema/context/spring-context.xsd
  12. http://www.springframework.org/schema/osgi-compendium
  13. http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd
  14. http://www.eclipse.org/gemini/blueprint/schema/blueprint
  15. http://www.eclipse.org/gemini/blueprint/schema/blueprint/gemini-blueprint.xsd">
  16. <osgix:cm-properties id="dbInfo" persistent-id="com.csdn.osgi.common">
  17. <prop key="driver">com.mysql.jdbc.Driver</prop>
  18. <prop key="url">jdbc:mysql://127.0.0.1:3306/osgi</prop>
  19. <prop key="username">root</prop>
  20. <prop key="password"></prop>
  21. </osgix:cm-properties>
  22. <ctx:property-placeholder properties-ref="dbInfo" />
  23. </beans>

接下来在Bean的定义中,就可以一${Key}的形式访问Value值了,例如:

  1. <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  2. <property name="driverClassName" value="${driver}" />
  3. <property name="url" value="${url}" />
  4. <property name="username" value="${username}" />
  5. <property name="password" value="${password}" />
  6. </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文件内容如下:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
  5. <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  6. <property name="driverClassName" value="${driver}" />
  7. <property name="url" value="${url}" />
  8. <property name="username" value="${username}" />
  9. <property name="password" value="${password}" />
  10. </bean>
  11. <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  12. <property name="dataSource" ref="dataSource" />
  13. <property name="configLocation" value="classpath:sqlMap.xml"/>
  14. </bean>
  15. <!-- 创建SqlSessionTemplate -->
  16. <bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
  17. <constructor-arg index="0" ref="sqlSessionFactory" />
  18. </bean>
  19. <!-- 事务管理 -->
  20. <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  21. <property name="dataSource" ref="dataSource" />
  22. </bean>
  23. <!--事务模板 -->
  24. <bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate">
  25. <property name="transactionManager">
  26. <ref local="transactionManager" />
  27. </property>
  28. <!--ISOLATION_DEFAULT 表示由使用的数据库决定 -->
  29. <property name="isolationLevelName" value="ISOLATION_DEFAULT"/>
  30. <property name="propagationBehaviorName" value="PROPAGATION_REQUIRED"/>
  31. </bean>
  32. </beans>

3、接下来在META-INF/spring目录下,新建一个dmconfig.xml文件,用于配置placeholder及注册sqlSessionTemplate这个Bean,这样在其他Bundle中就可以通过引用我们注册的sqlSessionTemplate来操作数据库了。

dmconfig.xml文件内容如下:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:osgix="http://www.springframework.org/schema/osgi-compendium"
  5. xmlns:ctx="http://www.springframework.org/schema/context"
  6. xmlns:osgi="http://www.eclipse.org/gemini/blueprint/schema/blueprint"
  7. xsi:schemaLocation="
  8. http://www.springframework.org/schema/beans
  9. http://www.springframework.org/schema/beans/spring-beans.xsd
  10. http://www.springframework.org/schema/context
  11. http://www.springframework.org/schema/context/spring-context.xsd
  12. http://www.springframework.org/schema/osgi-compendium
  13. http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd
  14. http://www.eclipse.org/gemini/blueprint/schema/blueprint
  15. http://www.eclipse.org/gemini/blueprint/schema/blueprint/gemini-blueprint.xsd">
  16. <osgix:cm-properties id="dbInfo" persistent-id="com.csdn.osgi.common">
  17. <prop key="driver">com.mysql.jdbc.Driver</prop>
  18. <prop key="url">jdbc:mysql://127.0.0.1:3306/osgi</prop>
  19. <prop key="username">root</prop>
  20. <prop key="password"></prop>
  21. </osgix:cm-properties>
  22. <ctx:property-placeholder properties-ref="dbInfo" />
  23. <osgi:service id="sqlMapService" ref="sqlSessionTemplate" interface="org.apache.ibatis.session.SqlSession" />
  24. </beans>

4、接下来就是Mybatis主配置文件和SQL的配置了,在sqlSessionFactory这个Bean的配置中,我们指定了Mybatis配置文件为sqlMap.xml,如下:

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

所以需要在com.csdn.osgi.database工程的src目录下新建一个sqlMap.xml文件,内容如下:

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

上面配置中,我们指定了SQL配置文件为user.xml,接着在com.csdn.osgi.database工程的src目录下新建user.xml文件,内容如下:

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="user">
  6. <insert id="saveUser" parameterType="java.util.HashMap">
  7. insert into user(username,password) values(#{UserName},#{Password});
  8. </insert>
  9. <select id="getPasswordByName" parameterType="java.lang.String" resultType="java.lang.String">
  10. select password from user where username = #{UserName}
  11. </select>
  12. </mapper>

5、整个工程目录及文件结构如下图所示:



6、然后还需要对com.csdn.osgi.database工程的MANIFEST.MF文件新建修改,添加如下Bundle的依赖:

  1. Manifest-Version: 1.0
  2. Bundle-ManifestVersion: 2
  3. Bundle-Name: Database
  4. Bundle-SymbolicName: com.csdn.osgi.database
  5. Bundle-Version: 1.0.0.qualifier
  6. Bundle-Vendor: CSDN
  7. Bundle-RequiredExecutionEnvironment: JavaSE-1.8
  8. Require-Bundle: org.springframework.jdbc;bundle-version="3.0.0",
  9. org.mybatis.mybatis;bundle-version="3.1.1",
  10. com.springsource.org.apache.commons.dbcp;bundle-version="1.2.2",
  11. com.springsource.org.apache.commons.pool;bundle-version="1.3.0",
  12. org.springframework.transaction;bundle-version="3.0.0",
  13. com.springsource.com.mysql.jdbc;bundle-version="5.1.6",
  14. org.mybatis.mybatis-spring;bundle-version="1.2.3"

上面MANIFEST.MF文件中,Require-Bundle元数据头为新增。

7、最后一步,启动OSGI容器。需要单击Run=>Debug Configurations…菜单,如下图所示:

单击Validate Bundles按钮,查看是否存在Bundle依赖问题,笔者单击后如下图所示:

说明存在依赖问题,解决方法非常简单,单击面板上的Add Required Bundles按钮即可。

启动后输出控制台输出日志内容如下:

  1. 一月 07, 2017 3:40:33 下午 org.eclipse.gemini.blueprint.extender.internal.boot.ChainActivator <init>
  2. 信息: Blueprint API detected; enabling Blueprint Container functionality
  3. 一月 07, 2017 3:40:33 下午 org.eclipse.gemini.blueprint.extender.internal.activator.LoggingActivator start
  4. 信息: Starting [org.eclipse.gemini.blueprint.extender] bundle v.[2.0.0.M02]
  5. osgi> 一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.extender.internal.support.ExtenderConfiguration start
  6. 信息: No custom extender configuration detected; using defaults...
  7. 一月 07, 2017 3:40:34 下午 org.springframework.scheduling.timer.TimerTaskExecutor afterPropertiesSet
  8. 信息: Initializing Timer
  9. hello world!
  10. 一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.extender.support.DefaultOsgiApplicationContextCreator createApplicationContext
  11. 信息: Discovered configurations {osgibundle:/META-INF/spring/*.xml} in bundle [Common (com.csdn.osgi.common)]
  12. Hello World!!
  13. 一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.extender.support.DefaultOsgiApplicationContextCreator createApplicationContext
  14. 信息: Discovered configurations {config/*.xml} in bundle [Helloworld (com.csdn.osgi.helloworld)]
  15. 一月 07, 2017 3:40:34 下午 org.springframework.context.support.AbstractApplicationContext prepareRefresh
  16. 信息: 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
  17. 一月 07, 2017 3:40:34 下午 org.springframework.context.support.AbstractApplicationContext prepareRefresh
  18. 信息: Refreshing OsgiBundleXmlApplicationContext(bundle=com.csdn.osgi.helloworld, config=config/*.xml): startup date [Sat Jan 07 15:40:34 CST 2017]; root of context hierarchy
  19. 一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.context.support.AbstractOsgiBundleApplicationContext unpublishContextAsOsgiService
  20. 信息: Application Context service already unpublished
  21. 一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.extender.internal.blueprint.activator.support.BlueprintContainerCreator createApplicationContext
  22. 信息: Discovered configurations {bundleentry://43.fwk2082351774/OSGI-INF/blueprint/beans.xml} in bundle [Helloworld (com.csdn.osgi.helloworld)]
  23. 一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.context.support.AbstractOsgiBundleApplicationContext unpublishContextAsOsgiService
  24. 信息: Application Context service already unpublished
  25. 一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.extender.support.DefaultOsgiApplicationContextCreator createApplicationContext
  26. 信息: Discovered configurations {osgibundle:/META-INF/spring/*.xml} in bundle [Database (com.csdn.osgi.database)]
  27. 一月 07, 2017 3:40:34 下午 org.springframework.context.support.AbstractApplicationContext prepareRefresh
  28. 信息: 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
  29. 一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.context.support.AbstractOsgiBundleApplicationContext unpublishContextAsOsgiService
  30. 信息: Application Context service already unpublished
  31. 一月 07, 2017 3:40:34 下午 org.springframework.context.support.AbstractApplicationContext prepareRefresh
  32. 信息: 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
  33. 一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.context.support.AbstractOsgiBundleApplicationContext unpublishContextAsOsgiService
  34. 信息: Application Context service already unpublished
  35. 一月 07, 2017 3:40:34 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
  36. 信息: Loading XML bean definitions from OSGi resource[bundleentry://43.fwk2082351774/OSGI-INF/blueprint/beans.xml|bnd.id=43|bnd.sym=com.csdn.osgi.helloworld]
  37. 一月 07, 2017 3:40:34 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
  38. 信息: Loading XML bean definitions from URL [bundleentry://37.fwk2082351774/META-INF/spring/beans.xml]
  39. 一月 07, 2017 3:40:34 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
  40. 信息: Loading XML bean definitions from URL [bundleentry://46.fwk2082351774/META-INF/spring/database.xml]
  41. 一月 07, 2017 3:40:34 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
  42. 信息: Loading XML bean definitions from URL [bundleentry://43.fwk2082351774/config/beans.xml]
  43. 一月 07, 2017 3:40:34 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
  44. 信息: Loading XML bean definitions from URL [bundleentry://43.fwk2082351774/config/company.xml]
  45. 一月 07, 2017 3:40:34 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
  46. 信息: Loading XML bean definitions from URL [bundleentry://46.fwk2082351774/META-INF/spring/dmconfig.xml]
  47. 一月 07, 2017 3:40:34 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
  48. 信息: Loading XML bean definitions from URL [bundleentry://37.fwk2082351774/META-INF/spring/dmconfig.xml]
  49. 一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor stageOne
  50. 信息: No outstanding OSGi service dependencies, completing initialization for OsgiBundleXmlApplicationContext(bundle=com.csdn.osgi.helloworld, config=bundleentry://43.fwk2082351774/OSGI-INF/blueprint/beans.xml)
  51. 一月 07, 2017 3:40:34 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
  52. 信息: Loading XML bean definitions from URL [bundleentry://43.fwk2082351774/config/dmconfig.xml]
  53. ================Hello World================
  54. 一月 07, 2017 3:40:34 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
  55. 信息: Loading XML bean definitions from URL [bundleentry://37.fwk2082351774/META-INF/spring/employee.xml]
  56. 一月 07, 2017 3:40:34 下午 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
  57. 信息: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@215dd7af: defining beans [helloWorld,blueprintBundle,blueprintBundleContext,blueprintContainer,blueprintConverter]; root of factory hierarchy
  58. 一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor stageOne
  59. 信息: No outstanding OSGi service dependencies, completing initialization for OsgiBundleXmlApplicationContext(bundle=com.csdn.osgi.common, config=osgibundle:/META-INF/spring/*.xml)
  60. 一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.blueprint.container.support.BlueprintContainerServicePublisher registerService
  61. 信息: 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}
  62. 一月 07, 2017 3:40:34 下午 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
  63. 信息: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@68bf15f1: defining beans [object,length,buffer,current-time,list,employee,programmer]; root of factory hierarchy
  64. 一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.context.support.AbstractOsgiBundleApplicationContext publishContextAsOsgiServiceIfNecessary
  65. 信息: 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}
  66. 一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.extender.internal.dependencies.startup.DependencyServiceManager doFindDependencies
  67. 信息: Adding OSGi service dependency for importer [&employee] matching OSGi filter [(objectClass=com.csdn.osgi.domain.Employee)]
  68. 一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.extender.internal.support.DefaultOsgiBundleApplicationContextListener onOsgiApplicationEvent
  69. 信息: Application context successfully refreshed (OsgiBundleXmlApplicationContext(bundle=com.csdn.osgi.helloworld, config=bundleentry://43.fwk2082351774/OSGI-INF/blueprint/beans.xml))
  70. 一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.extender.internal.dependencies.startup.DependencyServiceManager findServiceDependencies
  71. 信息: OsgiBundleXmlApplicationContext(bundle=com.csdn.osgi.helloworld, config=config/*.xml) is waiting for unsatisfied dependencies [[&employee]]
  72. 一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor stageOne
  73. 信息: No outstanding OSGi service dependencies, completing initialization for OsgiBundleXmlApplicationContext(bundle=com.csdn.osgi.database, config=osgibundle:/META-INF/spring/*.xml)
  74. 一月 07, 2017 3:40:34 下午 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
  75. 信息: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@30d1126b: defining beans [dataSource,sqlSessionFactory,sqlSessionTemplate,transactionManager,transactionTemplate,dbInfo,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,sqlMapService]; root of factory hierarchy
  76. 一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.service.exporter.support.OsgiServiceFactoryBean registerService
  77. 信息: Publishing service under classes [{com.csdn.osgi.domain.Employee}]
  78. 一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.extender.internal.dependencies.startup.DependencyServiceManager$DependencyServiceListener serviceChanged
  79. 信息: No unsatisfied OSGi service dependencies; completing initialization for OsgiBundleXmlApplicationContext(bundle=com.csdn.osgi.helloworld, config=config/*.xml)
  80. 一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.context.support.AbstractOsgiBundleApplicationContext publishContextAsOsgiServiceIfNecessary
  81. 信息: 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}
  82. 一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.extender.internal.support.DefaultOsgiBundleApplicationContextListener onOsgiApplicationEvent
  83. 信息: Application context successfully refreshed (OsgiBundleXmlApplicationContext(bundle=com.csdn.osgi.common, config=osgibundle:/META-INF/spring/*.xml))
  84. SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
  85. SLF4J: Defaulting to no-operation (NOP) logger implementation
  86. SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
  87. 一月 07, 2017 3:40:34 下午 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
  88. 信息: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@4f805c92: defining beans [helloWorld1,helloWorld2,company,employee]; root of factory hierarchy
  89. ================Hello World================
  90. ================Hello World================
  91. =========Company=========
  92. 一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.context.support.AbstractOsgiBundleApplicationContext publishContextAsOsgiServiceIfNecessary
  93. 信息: 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}
  94. 一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.extender.internal.support.DefaultOsgiBundleApplicationContextListener onOsgiApplicationEvent
  95. 信息: Application context successfully refreshed (OsgiBundleXmlApplicationContext(bundle=com.csdn.osgi.helloworld, config=config/*.xml))
  96. 一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.service.exporter.support.OsgiServiceFactoryBean registerService
  97. 信息: Publishing service under classes [{org.apache.ibatis.session.SqlSession}]
  98. 一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.context.support.AbstractOsgiBundleApplicationContext publishContextAsOsgiServiceIfNecessary
  99. 信息: 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}
  100. 一月 07, 2017 3:40:34 下午 org.eclipse.gemini.blueprint.extender.internal.support.DefaultOsgiBundleApplicationContextListener onOsgiApplicationEvent
  101. 信息: 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企业应用开发(九)整合Spring和Mybatis框架(二)的更多相关文章

  1. OSGI企业应用开发(八)整合Spring和Mybatis框架(一)

    到目前为止,我们已经学习了如何使用Blueprint將Spring框架整合到OSGI应用中,并学习了Blueprint&Gemini Blueprint的一些使用细节.本篇文章开始,我们將My ...

  2. OSGI企业应用开发(十)整合Spring和Mybatis框架(三)

    上篇文章中,我们已经完成了OSGI应用中Spring和Mybatis框架的整合,本文就来介绍一下,如何在其他Bundle中,使用Mybatis框架来操作数据库. 为了方便演示,我们新建一个新的Plug ...

  3. 框架整合——Spring与MyBatis框架整合

    Spring整合MyBatis 1. 整合 Spring [整合目标:在spring的配置文件中配置SqlSessionFactory以及让mybatis用上spring的声明式事务] 1). 加入 ...

  4. OSGI企业应用开发(十二)OSGI Web应用开发(一)

    前面文章中介绍了如何在OSGI应用中整合Spring和Mybatis框架,本篇文章开始介绍如何使用OSGI技术开发Web应用.对于传统的Java EE应用,应用中涉及到的Web元素无非就是Servle ...

  5. 搭建Spring + SpringMVC + Mybatis框架之二(整合Spring和Mybatis)

    整合Spring和Mybatis 首先给出完整的项目目录: (1)引入项目需要的jar包 使用http://maven.apache.org作为中央仓库即可. Spring核心包,mybatis核心包 ...

  6. 用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建二:配置MyBatis 并测试(2 配置spring-dao和测试)

    用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建二:配置MyBatis 并测试(1 搭建目录环境和依赖) 四:在\resources\spring 下面 ...

  7. 用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建二:配置MyBatis 并测试(1 构建目录环境和依赖)

    引言:在用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建一   的基础上 继续进行项目搭建 该部分的主要目的是测通MyBatis 及Spring-dao ...

  8. 用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建一:建立MAVEN Web项目

    一:创建maven web项目er

  9. 使用maven整合spring+springmvc+mybatis

    使用maven整合spring+springmvc+mybatis 开发环境: 1. jdk1.8 2. eclipse4.7.0 (Oxygen) 3. mysql 5.7 在pom.xml文件中, ...

随机推荐

  1. [0day]微软XP系统右键菜单任意DLL却持

    作者:K8哥哥只要在DLL上右键就被却持 任意DLL名称 任意位置 (其实是EXPLOR) 这个漏洞早已存在,08年的时候就发现了(当时编译某个DLL源码) 在DLL上右键看属性的时候崩溃了,当时就想 ...

  2. Webstorm使用教程详解

    Webstorm使用教程详解 Webstorm垂直分栏.左右分栏 Webstorm 主题.背景.颜色等设置的导入导出   使用WebStorm开发web前端 网页中文乱码问题的解决方案 Webstor ...

  3. 阿里语音识别(语音转文字)java调用全程手把手详解-适合中小学生快速上手

    阿里语音识别服务java调用全程手把手详解-适合中小学生快速上手 阿里语音识别与百度语音识别的调用对比: 用例:1分30秒的录音文件    百度用时:3秒    阿里用时:30秒    识别准确率来看 ...

  4. N元马尔科夫链的实现

    马尔可夫模型(Markov Model)是一种统计模型,广泛应用在语音识别,词性自动标注,音字转换,概率文法等各个自然语言处理等应用领域.经过长期发展,尤其是在语音识别中的成功应用,使它成为一种通用的 ...

  5. nginx服务器搭建以及配置

    2019年第一篇博客,在新的一年祝大家新年快乐,技术更上一层楼. 今天在公司搞了好长时间的nginx服务器搭建,以及遇到的问题,总结一下,方便查询 这里使用的是百度云的服务器,CentOS7系统的 N ...

  6. List集合中的对象按照某个字段去重实现

    package com.liying.banana.user; import java.util.ArrayList; import java.util.Comparator; import java ...

  7. Linux-(rcp,scp)

    rcp命令 1.命令格式: rcp [参数] [源文件] [目标文件] 2.命令功能: rcp命令用在远端复制文件或目录,如同时指定两个以上的文件或目录,且最后的目的地是一个已经存在的目录,则它会把前 ...

  8. javaweb的web.xml配置说明,初始化过程

    [重点]初始化过程可知容器对于web.xml的加载过程是context-param >> listener  >> fileter  >> servlet 首先了解 ...

  9. goconfig - INI 解析器

    goconfig简介 goconfig是一个由Go语言开发的针对windows下常见的ini格式的配置文件解析器.该解析器在涵盖了所有ini文件操作的基础之上,又针对Go语言实际开发过程中遇到的一些需 ...

  10. 【一个小功能】点击图标/链接发起QQ临时会话

    有时候,我们需要实现在网页上点击一个QQ图标来实现QQ临时会话,这样不用添加好友,也能满足及时沟通的需求. 实现方案比较简单,只是为a标签修改href属性,代码如下 <a href=" ...