Blueprint除了组装bean,osgi服务引用等的DI(IOC)功能之外,还可通过各种命名空间(namespace)来扩展。在《
Blueprint入门之六》中,我们就用过一个与ConfigAdmin相关的命名空间(http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0)。
除了ConfigAdmin之外,我们还可以看到aries JPA container提供了JPA相关的blueprint命名空间(http://aries.apache.org/xmlns/jpa/v1.1.0) ,Aries JPA Container根据bundle中的persistence.xml构建持久化域单元(persistence domain unit)后,需要将相应的EntityManagerFactory或EntityManager注入到需要用到该持久化域的bean实例里,就可以使用这个命名空间。
persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name=" com.ponder.myPU " transaction-type="RESOURCE_LOCAL">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<non-jta-data-source>
osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/myDS)
</non-jta-data-source>
<class>com.ponder.*</class>
<properties>
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
</properties>
</persistence-unit>
</persistence>
注:以上persistence.xml中的(osgi.jndi.service.name=jdbc/myDS)是将注册到jndi的jdbc的数据源注入进来。
注入EntityManagerFactory:
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:jpa="http://aries.apache.org/xmlns/jpa/v1.1.0" >
<bean id="processor1" class="com.ponder.processor">
<jpa:unit property="emf" unitname="com.ponder.myPU" />
</bean>
... ....
</blueprint>
注入EntityManager:
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:jpa="http://aries.apache.org/xmlns/jpa/v1.1.0" >
<bean id="processor1" class="com.ponder.processor">
<jpa:context property="em" unitname="com.ponder.myPU" />
</bean>
... ....
</blueprint>
在事务(Transaction)方面,Blueprint通过命名空间(xmlns:tx="http://aries.apache.org/xmlns/transactions/v1.0.0)支持声明式事务(Declaractive Transaction):
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:jpa="http://aries.apache.org/xmlns/jpa/v1.0.0"
xmlns:tx="http://aries.apache.org/xmlns/transactions/v1.0.0">
<bean id="processor1" class="com.ponder.processor">
<jpa:context property="em" unitname="com.ponder.myPU" />
<tx:transaction method="*" value="Required" />
</bean>
... ...
</blueprint>
分享到:
相关推荐
OSGi的入门资料,网上找的,初探OSGi 的全文
OSGi的入门教程,帮助初学者快速了解OSGi的定义、用途及组成。
强大的OSGI框架入门和例子,看看eclipse就知道OSGI有多强大了。希望对大家有用!
OSGI 入门资料PDF,包括OSGI实战、OSGI进阶、OSGI 入门和整合Spring、OSGI原理与最佳实践
osgi-blueprint-helloworld 概述 一个使用OSGI蓝图容器规范的非常简单的HelloWorld示例。 想要查询更多的信息: osgi-blueprint-helloworld-api 应用程序API osgi-blueprint-helloworld-server 发布服务以供...
Spring OSGI 快速入门中文教程
NULL 博文链接:https://conkeyn.iteye.com/blog/2113824
OSGI简单入门.doc
osgi webservice入门
OSGI入门和整合Spring OSGI入门和整合Spring
spring-osgi 入门手册和代码 spring-osgi 入门手册和代码 spring-osgi 入门手册和代码 spring-osgi 入门手册和代码
总结了osgi服务发布和获取的多种方式。
Spring OSGi 入门.pdf Spring OSGi 入门.pdf
OSGI入门和整合Spring + OSGI进阶 + OSGI实战
OSGi 入门级教程OSGi 入门级教程OSGi 入门级教程OSGi 入门级教程中文版
blueprint-osgi-bundle
关于SOA中热门技术OSGI的入门样例的经典版本,供对需要进行ERP设计和学习的入门读者使用的经典
资源名称:OSGI原理与最佳实践内容简介:国内第一本OSGi图书OSGi国内推广者林昊多年经验的结晶涵盖OSGi从入门到深入的知识体系引领OSGi国内研究和普及本书基于作者多年使用OSGi的经验而编写,涵盖了OSGi从入门到深入...
OSGI进阶.pdf,OSGI实战.pdf,OSGI入门和整合Spring.pdf