The DataSource
bundle creates an in memory HSQL database and
creates a connection pool that is exposed as an OSGi DataSource
service.
The manifest defines the bundles symbolic name, and imports javax.sql
, Spring, HSQL DB, and Commons DBCP.
Note | |
---|---|
If when opening the manifest and viewing the Dependencies tab in the Ecilpse IDE, there isn't an 'Import Bundle' section on the right and an 'Import Library' section underneath it the default Eclipse manifest editor may have been opened. To open the Spring manifest editor, right click, 'Open with'/'Other...', and then choose the 'Bundle Manifest Editor'. |
Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Simple Spring MVC Form DataSource Bundle Bundle-Description: Simple Spring MVC Form DataSource Bundle-SymbolicName: org.springbyexample.sdms.simpleForm.datasource Bundle-Version: 1.0.0 Bundle-Vendor: Spring by Example Import-Package: javax.sql Import-Library: org.springframework.spring;version="[2.5.5,3.0.0)" Import-Bundle: com.springsource.org.hsqldb;version="[1.8.0,2.0.0)", com.springsource.org.apache.commons.dbcp;version="[1.2.2.osgi,1.3.0)"
By default any spring configuration files in the META-INF/spring will be processed (this is configurable). A connection pool is created using Commons DBCP to an HSQL DB and then the pool is exposed as an OSGi service.
<?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="org.hsqldb.jdbcDriver" /> <property name="url" value="jdbc:hsqldb:mem:person" /> <property name="username" value="sa" /> <property name="password" value="" /> </bean> </beans>
The Spring Dynamic Modules' namespace is
setup as the default namespace for the configuration file. The service
element exposes the dataSource bean as an OSGi service under the
interface javax.sql.DataSource
.
<?xml version="1.0" encoding="UTF-8"?> <beans:beans xmlns="http://www.springframework.org/schema/osgi" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans" xsi:schemaLocation="http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi-1.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <service ref="dataSource" interface="javax.sql.DataSource" /> </beans:beans>