...
Another feature that I would like to introduce here concerns the Configuration Admin. In its simplest form, the CM can be seen as a configuration source, namely a Dictionary whose keys are always Strings. Spring DM can expose entries in the CM as a Properties object, through the cm-properties element. A minimal declaration looks as follows:
So, we can adapt our {{}} file created in the previous chapter with new xml tags :
Code Block |
---|
<context:property-placeholder properties-ref="preProps" /> (1)
...
<osgix:cm-properties id="preProps" persistent-id="org.apache.camel.example.reportincident.datasource"> (2)
<prop key="driverClassName">com.mysql.jdbc.Driver</prop>
<prop key="url">jdbc:mysql:///report</prop>
<prop key="username"></prop>
<prop key="password"></prop>
</osgix:cm-properties>
...
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${driverClassName}" /> (3)
<property name="url" value="${url}" />
<property name="username" value="${username}" />
<property name="password" value="${password}" />
</bean>
|
The configuration above, exposes the properties available in the CM under data.source.office.1 entry org.apache.camel.example.reportincident.datasource
entry (2) as a bean named ds.cfgpreProps. Moreover, we will create 'for the deployment' a file 'org.apache.camel.example.reportincident.datasource.cfg' that the OSGI registry service will use to instantiate the preporties.
Remarks :
the property declared (3) can be override by creating a file named org.apache.camel.example.reportincident.datasource.cfg
and containing the parameters :
Code Block |
---|
driverClassName=com.mysql.jdbc.Driver
url=jdbc:mysql:///report
username=root
password=
|
Spring using the context:property-placeholder
(1) will be able to load it.
Remarks :
- We will see in the chapter 'deployment' where this file must be deployedIf the file is not found, the properties declared in the spring xml file will be used.
- In our example, we have only defined
properties
for thedriver
,username
and {{password }} but you can extend the list of values with by example Hibernate parameters like hibernate.show_sql, hibernate.format_sql, ...
...