[ 
https://issues.apache.org/jira/browse/KARAF-5913?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16722276#comment-16722276
 ] 

ASF GitHub Bot commented on KARAF-5913:
---------------------------------------

jbonofre closed pull request #704: [KARAF-5913] Add config example
URL: https://github.com/apache/karaf/pull/704
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/examples/karaf-config-example/README.md 
b/examples/karaf-config-example/README.md
new file mode 100644
index 0000000000..d104c61756
--- /dev/null
+++ b/examples/karaf-config-example/README.md
@@ -0,0 +1,212 @@
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+-->
+# Apache Karaf Configuration Example
+
+## Abstract
+
+This example shows how to use configuration in your application, introducing 
different approach:
+
+* the static approach using `ConfigurationAdmin` service, where the 
configuration is loaded once, on demand.
+* the `ManagedService` approach which is dynamic. Your application receives a 
notification when the configuration changes.
+* the `ManagedServiceFactory` dynamic approach that can handle several 
configurations created.
+* the `ConfigurationListener` approach is able to listen for any change in all 
configurations.
+* the `blueprint` approach is similar to `Managed` dynamic approach using 
blueprint
+* the `scr` approach is similar to `Managed` dynamic approach using scr
+
+During the installation of a configuration example feature, a configuration is 
created with the `org.apache.karaf.example.config` persistent id.
+The configuration uses `etc/org.apache.karaf.example.config.cfg` configuration 
file.
+
+## Artifacts
+
+* **karaf-config-example-static** uses the `ConfigurationAdmin` service to 
retrieve the configuration identified by a PID (Persistent ID).
+* **karaf-config-example-managed** uses the dynamic approach exposing a 
`Managed` service.
+* **karaf-config-example-managed-factory** dealing with several configurations 
created using a `ManagedFactory` service.
+* **karaf-config-example-listener** listens for any change in any 
configuration.
+* **karaf-config-example-blueprint** uses configuration within a blueprint 
container.
+* **karaf-config-example-scr** uses configuration within a scr component.
+* **karaf-config-example-features** contains a Apache Karaf features 
repository used for deployment.
+
+## Build
+
+The build uses Apache Maven. Simply use:
+
+```
+mvn clean install
+```
+
+## Feature and Deployment
+
+On a running Karaf instance, register the features repository using:
+
+```
+karaf@root()> feature:repo-add 
mvn:org.apache.karaf.examples/karaf-config-example-features/4.2.2-SNAPSHOT/xml
+```
+
+## Usage
+
+### Static
+
+If you install the `karaf-config-example-static` feature, it will create the 
`etc/org.apache.karaf.example.config.cfg` configuration file with the
+`org.apache.karaf.example.config` configuration. At startup, the 
`karaf-config-example-static` feature will display the content of the 
configuration:
+
+```
+karaf@root()> feature:install karaf-config-example-static 
+felix.fileinstall.filename = 
file:/home/jbonofre/Workspace/karaf/assemblies/apache-karaf/target/apache-karaf-4.2.2-SNAPSHOT/etc/org.apache.karaf.example.config.cfg
+foo = bar
+hello = world
+org.apache.karaf.features.configKey = org.apache.karaf.example.config
+service.pid = org.apache.karaf.example.config
+```
+
+### Managed
+
+You can also test the dynamic approach using `karaf-config-example-managed` 
feature:
+
+```
+karaf@root()> feature:install karaf-config-example-managed
+```
+
+Then, you can install the `karaf-config-example-common` feature providing the 
configuration. Then, you can see the managed service called:
+
+```
+karaf@root()> feature:install karaf-config-example-common
+Configuration changed
+felix.fileinstall.filename = 
file:/home/jbonofre/Workspace/karaf/assemblies/apache-karaf/target/apache-karaf-4.2.2-SNAPSHOT/etc/org.apache.karaf.example.config.cfg
+foo = bar
+org.apache.karaf.features.configKey = org.apache.karaf.example.config
+service.pid = org.apache.karaf.example.config
+```
+
+If you change the configuration (using `config:edit` command), you can see 
also the managed service called:
+
+```
+karaf@root()> config:edit org.apache.karaf.example.config
+karaf@root()> config:property-set hello world
+karaf@root()> config:update
+Configuration changed
+felix.fileinstall.filename = 
file:/home/jbonofre/Workspace/karaf/assemblies/apache-karaf/target/apache-karaf-4.2.2-SNAPSHOT/etc/org.apache.karaf.example.config.cfg
+foo = bar
+hello = world
+org.apache.karaf.features.configKey = org.apache.karaf.example.config
+service.pid = org.apache.karaf.example.config
+```
+
+### Managed factory
+
+The managed service factory approach allows you to deal with several 
configurations of the same kind. The "base" pid is 
`org.apache.karaf.example.config`, then you ca
+create a new configuration based on this one. For instance, you can create 
`etc/org.apache.karaf.example.config-example.cfg` containing:
+
+```
+hello=world
+```
+
+Then you will see in the Karaf shell console:
+
+```
+karaf@root()> New configuration with pid 
org.apache.karaf.example.config.994408d3-b950-4ef5-9cf0-eaaad97922f3
+felix.fileinstall.filename = 
file:/home/jbonofre/Workspace/karaf/assemblies/apache-karaf/target/apache-karaf-4.2.2-SNAPSHOT/etc/org.apache.karaf.example.config-test.cfg
+hello = world
+service.factoryPid = org.apache.karaf.example.config
+service.pid = 
org.apache.karaf.example.config.994408d3-b950-4ef5-9cf0-eaaad97922f3
+```
+
+If you remove `etc/org.apache.karaf.example.config-example.cfg` file, you will 
see:
+
+```
+Delete configuration with pid 
org.apache.karaf.example.config.994408d3-b950-4ef5-9cf0-eaaad97922f3
+```
+
+### Configuration listener
+
+The `karaf-config-example-listener` feature installs a configuration listener:
+
+```
+karaf@root()> feature:install karaf-config-example-listener
+```
+
+Then you can create `etc/my.config.cfg` configuration file, you will see:
+
+```
+Configuration my.config has been updated
+```
+
+If you delete `etc/my.config.cfg` configuration file, you will see:
+
+```
+Configuration my.config has been deleted
+```
+
+### Blueprint
+
+Apache Aries Blueprint provides Blueprint CM that deals with configuration.
+
+Especially, you can use a property placeholder to easily load a configuration 
and inject some properties in your bean.
+
+It's what we do in the `karaf-config-example-blueprint` feature:
+
+```
+karaf@root()> feature:install karaf-config-example-blueprint
+```
+
+You will see:
+
+```
+hello = world
+```
+
+Then, if you change `etc/org.apache.karaf.example.config.cfg` file to set 
`hello` property value to `other`, you will see:
+
+```
+hello = other
+```
+
+### SCR
+
+SCR natively supports configuration.
+
+It's what `karaf-config-example-scr` feature is using:
+
+```
+karaf@root()> karaf-config-example-scr
+```
+
+At installation time, we can see the configuration display:
+
+```
+service.pid = org.apache.karaf.example.config
+hello = world
+org.apache.karaf.features.configKey = org.apache.karaf.example.config
+component.name = my-component
+felix.fileinstall.filename = 
file:/home/jbonofre/Workspace/karaf/assemblies/apache-karaf/target/apache-karaf-4.2.2-SNAPSHOT/etc/org.apache.karaf.example.config.cfg
+component.id = 1
+foo = bar
+```
+
+Then, we can add a new property in `etc/org.apache.karaf.example.config.cfg` 
configuration file, it's displayed by the SCR component:
+
+```
+service.pid = org.apache.karaf.example.config
+hello = world
+org.apache.karaf.features.configKey = org.apache.karaf.example.config
+component.name = my-component
+felix.fileinstall.filename = 
file:/home/jbonofre/Workspace/karaf/assemblies/apache-karaf/target/apache-karaf-4.2.2-SNAPSHOT/etc/org.apache.karaf.example.config.cfg
+component.id = 1
+foo = bar
+test = other
+```
\ No newline at end of file
diff --git 
a/examples/karaf-config-example/karaf-config-example-blueprint/pom.xml 
b/examples/karaf-config-example/karaf-config-example-blueprint/pom.xml
new file mode 100644
index 0000000000..dba60ddf4d
--- /dev/null
+++ b/examples/karaf-config-example/karaf-config-example-blueprint/pom.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+
+    <!--
+
+        Licensed to the Apache Software Foundation (ASF) under one or more
+        contributor license agreements.  See the NOTICE file distributed with
+        this work for additional information regarding copyright ownership.
+        The ASF licenses this file to You under the Apache License, Version 2.0
+        (the "License"); you may not use this file except in compliance with
+        the License.  You may obtain a copy of the License at
+
+           http://www.apache.org/licenses/LICENSE-2.0
+
+        Unless required by applicable law or agreed to in writing, software
+        distributed under the License is distributed on an "AS IS" BASIS,
+        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
implied.
+        See the License for the specific language governing permissions and
+        limitations under the License.
+    -->
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.karaf.examples</groupId>
+        <artifactId>karaf-config-example</artifactId>
+        <version>4.2.2-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>karaf-config-example-blueprint</artifactId>
+    <packaging>bundle</packaging>
+    <name>Apache Karaf :: Examples :: Configuration :: Blueprint</name>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
\ No newline at end of file
diff --git 
a/examples/karaf-config-example/karaf-config-example-blueprint/src/main/java/org/apache/karaf/example/config/blueprint/DisplayBean.java
 
b/examples/karaf-config-example/karaf-config-example-blueprint/src/main/java/org/apache/karaf/example/config/blueprint/DisplayBean.java
new file mode 100644
index 0000000000..381fa1924f
--- /dev/null
+++ 
b/examples/karaf-config-example/karaf-config-example-blueprint/src/main/java/org/apache/karaf/example/config/blueprint/DisplayBean.java
@@ -0,0 +1,35 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.karaf.example.config.blueprint;
+
+public class DisplayBean {
+
+    private String hello;
+
+    public String getHello() {
+        return hello;
+    }
+
+    public void setHello(String hello) {
+        this.hello = hello;
+    }
+
+    public void display() {
+        System.out.println("hello = " + hello);
+    }
+
+}
diff --git 
a/examples/karaf-config-example/karaf-config-example-blueprint/src/main/resources/OSGI-INF/blueprint/config.xml
 
b/examples/karaf-config-example/karaf-config-example-blueprint/src/main/resources/OSGI-INF/blueprint/config.xml
new file mode 100644
index 0000000000..d602eba381
--- /dev/null
+++ 
b/examples/karaf-config-example/karaf-config-example-blueprint/src/main/resources/OSGI-INF/blueprint/config.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0";
+    xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0";>
+
+    <cm:property-placeholder persistent-id="org.apache.karaf.example.config" 
update-strategy="reload">
+        <cm:default-properties>
+            <cm:property name="hello" value="world"/>
+        </cm:default-properties>
+    </cm:property-placeholder>
+
+    <bean id="display" 
class="org.apache.karaf.example.config.blueprint.DisplayBean" 
init-method="display">
+        <property name="hello" value="${hello}"/>
+    </bean>
+
+</blueprint>
\ No newline at end of file
diff --git 
a/examples/karaf-config-example/karaf-config-example-features/pom.xml 
b/examples/karaf-config-example/karaf-config-example-features/pom.xml
new file mode 100644
index 0000000000..1f9b79d422
--- /dev/null
+++ b/examples/karaf-config-example/karaf-config-example-features/pom.xml
@@ -0,0 +1,99 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+
+    <!--
+
+        Licensed to the Apache Software Foundation (ASF) under one or more
+        contributor license agreements.  See the NOTICE file distributed with
+        this work for additional information regarding copyright ownership.
+        The ASF licenses this file to You under the Apache License, Version 2.0
+        (the "License"); you may not use this file except in compliance with
+        the License.  You may obtain a copy of the License at
+
+           http://www.apache.org/licenses/LICENSE-2.0
+
+        Unless required by applicable law or agreed to in writing, software
+        distributed under the License is distributed on an "AS IS" BASIS,
+        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
implied.
+        See the License for the specific language governing permissions and
+        limitations under the License.
+    -->
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.karaf.examples</groupId>
+        <artifactId>karaf-config-example</artifactId>
+        <version>4.2.2-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>karaf-config-example-features</artifactId>
+    <packaging>pom</packaging>
+    <name>Apache Karaf :: Examples :: Configuration :: Features</name>
+
+    <build>
+        <resources>
+            <resource>
+                <directory>src/main/feature</directory>
+                <filtering>true</filtering>
+                <targetPath>${project.build.directory}/feature</targetPath>
+            </resource>
+        </resources>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-resources-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>resources</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+            <!--
+            <plugin>
+                <groupId>org.apache.karaf.tooling</groupId>
+                <artifactId>karaf-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>verify</id>
+                        <phase>process-resources</phase>
+                        <goals>
+                            <goal>verify</goal>
+                        </goals>
+                        <configuration>
+                            <descriptors>
+                                
<descriptor>file:${project.build.directory}/feature/feature.xml</descriptor>
+                            </descriptors>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            -->
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>build-helper-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>attach-artifacts</id>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>attach-artifact</goal>
+                        </goals>
+                        <configuration>
+                            <artifacts>
+                                <artifact>
+                                    <file>target/feature/feature.xml</file>
+                                    <type>xml</type>
+                                </artifact>
+                            </artifacts>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
\ No newline at end of file
diff --git 
a/examples/karaf-config-example/karaf-config-example-features/src/main/feature/feature.xml
 
b/examples/karaf-config-example/karaf-config-example-features/src/main/feature/feature.xml
new file mode 100644
index 0000000000..1897474e89
--- /dev/null
+++ 
b/examples/karaf-config-example/karaf-config-example-features/src/main/feature/feature.xml
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<features name="karaf-config-example-${project.version}" 
xmlns="http://karaf.apache.org/xmlns/features/v1.4.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://karaf.apache.org/xmlns/features/v1.4.0";>
+
+    <feature name="karaf-config-example-common" version="${project.version}">
+        <config name="org.apache.karaf.example.config">
+            hello=world
+            foo=bar
+        </config>
+    </feature>
+
+    <feature name="karaf-config-example-static" version="${project.version}">
+        <feature version="${project.version}" 
prerequisite="true">karaf-config-example-common</feature>
+        
<bundle>mvn:org.apache.karaf.examples/karaf-config-example-static/${project.version}</bundle>
+    </feature>
+
+    <feature name="karaf-config-example-managed" version="${project.version}">
+        
<bundle>mvn:org.apache.karaf.examples/karaf-config-example-managed/${project.version}</bundle>
+    </feature>
+
+    <feature name="karaf-config-example-managed-factory" 
version="${project.version}">
+        
<bundle>mvn:org.apache.karaf.examples/karaf-config-example-managed-factory/${project.version}</bundle>
+    </feature>
+
+    <feature name="karaf-config-example-listener" version="${project.version}">
+        
<bundle>mvn:org.apache.karaf.examples/karaf-config-example-listener/${project.version}</bundle>
+    </feature>
+
+    <feature name="karaf-config-example-blueprint" 
version="${project.version}">
+        <feature prerequisite="true">aries-blueprint</feature>
+        <feature prerequisite="true" 
version="${project.version}">karaf-config-example-common</feature>
+        
<bundle>mvn:org.apache.karaf.examples/karaf-config-example-blueprint/${project.version}</bundle>
+    </feature>
+
+    <feature name="karaf-config-example-scr" version="${project.version}">
+        <feature prerequisite="true">scr</feature>
+        <feature prerequisite="true" 
version="${project.version}">karaf-config-example-common</feature>
+        
<bundle>mvn:org.apache.karaf.examples/karaf-config-example-scr/${project.version}</bundle>
+    </feature>
+
+</features>
diff --git 
a/examples/karaf-config-example/karaf-config-example-listener/pom.xml 
b/examples/karaf-config-example/karaf-config-example-listener/pom.xml
new file mode 100644
index 0000000000..7805360a9e
--- /dev/null
+++ b/examples/karaf-config-example/karaf-config-example-listener/pom.xml
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+
+    <!--
+
+        Licensed to the Apache Software Foundation (ASF) under one or more
+        contributor license agreements.  See the NOTICE file distributed with
+        this work for additional information regarding copyright ownership.
+        The ASF licenses this file to You under the Apache License, Version 2.0
+        (the "License"); you may not use this file except in compliance with
+        the License.  You may obtain a copy of the License at
+
+           http://www.apache.org/licenses/LICENSE-2.0
+
+        Unless required by applicable law or agreed to in writing, software
+        distributed under the License is distributed on an "AS IS" BASIS,
+        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
implied.
+        See the License for the specific language governing permissions and
+        limitations under the License.
+    -->
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.karaf.examples</groupId>
+        <artifactId>karaf-config-example</artifactId>
+        <version>4.2.2-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>karaf-config-example-listener</artifactId>
+    <packaging>bundle</packaging>
+    <name>Apache Karaf :: Examples :: Configuration :: Listener</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>osgi.core</artifactId>
+            <version>6.0.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>osgi.cmpn</artifactId>
+            <version>6.0.0</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <configuration>
+                    <instructions>
+                        
<Bundle-Activator>org.apache.karaf.example.config.listener.Activator</Bundle-Activator>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
\ No newline at end of file
diff --git 
a/examples/karaf-config-example/karaf-config-example-listener/src/main/java/org/apache/karaf/example/config/listener/Activator.java
 
b/examples/karaf-config-example/karaf-config-example-listener/src/main/java/org/apache/karaf/example/config/listener/Activator.java
new file mode 100644
index 0000000000..eb9cd47a4e
--- /dev/null
+++ 
b/examples/karaf-config-example/karaf-config-example-listener/src/main/java/org/apache/karaf/example/config/listener/Activator.java
@@ -0,0 +1,52 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.karaf.example.config.listener;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.cm.ConfigurationEvent;
+import org.osgi.service.cm.ConfigurationListener;
+
+public class Activator implements BundleActivator {
+
+    private ServiceRegistration<ConfigurationListener> registration;
+
+    @Override
+    public void start(BundleContext bundleContext) {
+        ConfigurationListener listener = event ->  {
+            if (event.getType() == ConfigurationEvent.CM_DELETED) {
+                System.out.println("Configuration " + event.getPid() + " has 
been deleted");
+            }
+            if (event.getType() == ConfigurationEvent.CM_UPDATED) {
+                System.out.println("Configuration " + event.getPid() + " has 
been updated");
+            }
+            if (event.getType() == ConfigurationEvent.CM_LOCATION_CHANGED) {
+                System.out.println("Configuration " + event.getPid() + " 
location has been changed");
+            }
+        };
+        registration = 
bundleContext.registerService(ConfigurationListener.class, listener, null);
+    }
+
+    @Override
+    public void stop(BundleContext bundleContext) {
+        if (registration != null) {
+            registration.unregister();
+        }
+    }
+
+}
diff --git 
a/examples/karaf-config-example/karaf-config-example-managed-factory/pom.xml 
b/examples/karaf-config-example/karaf-config-example-managed-factory/pom.xml
new file mode 100644
index 0000000000..28bdf49f88
--- /dev/null
+++ b/examples/karaf-config-example/karaf-config-example-managed-factory/pom.xml
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+
+    <!--
+
+        Licensed to the Apache Software Foundation (ASF) under one or more
+        contributor license agreements.  See the NOTICE file distributed with
+        this work for additional information regarding copyright ownership.
+        The ASF licenses this file to You under the Apache License, Version 2.0
+        (the "License"); you may not use this file except in compliance with
+        the License.  You may obtain a copy of the License at
+
+           http://www.apache.org/licenses/LICENSE-2.0
+
+        Unless required by applicable law or agreed to in writing, software
+        distributed under the License is distributed on an "AS IS" BASIS,
+        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
implied.
+        See the License for the specific language governing permissions and
+        limitations under the License.
+    -->
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.karaf.examples</groupId>
+        <artifactId>karaf-config-example</artifactId>
+        <version>4.2.2-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>karaf-config-example-managed-factory</artifactId>
+    <packaging>bundle</packaging>
+    <name>Apache Karaf :: Examples :: Configuration :: Managed Factory</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>osgi.core</artifactId>
+            <version>6.0.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>osgi.cmpn</artifactId>
+            <version>6.0.0</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <configuration>
+                    <instructions>
+                        
<Bundle-Activator>org.apache.karaf.example.config.managedfactory.Activator</Bundle-Activator>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
\ No newline at end of file
diff --git 
a/examples/karaf-config-example/karaf-config-example-managed-factory/src/main/java/org/apache/karaf/example/config/managedfactory/Activator.java
 
b/examples/karaf-config-example/karaf-config-example-managed-factory/src/main/java/org/apache/karaf/example/config/managedfactory/Activator.java
new file mode 100644
index 0000000000..6912ff8bac
--- /dev/null
+++ 
b/examples/karaf-config-example/karaf-config-example-managed-factory/src/main/java/org/apache/karaf/example/config/managedfactory/Activator.java
@@ -0,0 +1,69 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.karaf.example.config.managedfactory;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedServiceFactory;
+
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+public class Activator implements BundleActivator {
+
+    private ServiceRegistration<ManagedServiceFactory> registration;
+
+    @Override
+    public void start(BundleContext bundleContext) {
+        ManagedServiceFactory factory = new ManagedServiceFactory() {
+            @Override
+            public String getName() {
+                return "Example Managed Factory";
+            }
+
+            @Override
+            public void updated(String pid, Dictionary<String, ?> properties) 
throws ConfigurationException {
+                System.out.println("New configuration with pid " + pid);
+                Enumeration<String> keys = properties.keys();
+                while (keys.hasMoreElements()) {
+                    String key = keys.nextElement();
+                    System.out.println(key + " = " + properties.get(key));
+                }
+            }
+
+            @Override
+            public void deleted(String pid) {
+                System.out.println("Delete configuration with pid " + pid);
+            }
+        };
+        Hashtable<String, String> serviceProperties = new Hashtable<>();
+        serviceProperties.put(Constants.SERVICE_PID, 
"org.apache.karaf.example.config");
+        registration = 
bundleContext.registerService(ManagedServiceFactory.class, factory, 
serviceProperties);
+    }
+
+    @Override
+    public void stop(BundleContext bundleContext) {
+        if (registration != null) {
+            registration.unregister();
+        }
+    }
+
+}
diff --git a/examples/karaf-config-example/karaf-config-example-managed/pom.xml 
b/examples/karaf-config-example/karaf-config-example-managed/pom.xml
new file mode 100644
index 0000000000..a57e31135d
--- /dev/null
+++ b/examples/karaf-config-example/karaf-config-example-managed/pom.xml
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+
+    <!--
+
+        Licensed to the Apache Software Foundation (ASF) under one or more
+        contributor license agreements.  See the NOTICE file distributed with
+        this work for additional information regarding copyright ownership.
+        The ASF licenses this file to You under the Apache License, Version 2.0
+        (the "License"); you may not use this file except in compliance with
+        the License.  You may obtain a copy of the License at
+
+           http://www.apache.org/licenses/LICENSE-2.0
+
+        Unless required by applicable law or agreed to in writing, software
+        distributed under the License is distributed on an "AS IS" BASIS,
+        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
implied.
+        See the License for the specific language governing permissions and
+        limitations under the License.
+    -->
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.karaf.examples</groupId>
+        <artifactId>karaf-config-example</artifactId>
+        <version>4.2.2-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>karaf-config-example-managed</artifactId>
+    <packaging>bundle</packaging>
+    <name>Apache Karaf :: Examples :: Configuration :: Managed</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>osgi.core</artifactId>
+            <version>6.0.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>osgi.cmpn</artifactId>
+            <version>6.0.0</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <configuration>
+                    <instructions>
+                        
<Bundle-Activator>org.apache.karaf.example.config.managed.Activator</Bundle-Activator>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
\ No newline at end of file
diff --git 
a/examples/karaf-config-example/karaf-config-example-managed/src/main/java/org/apache/karaf/example/config/managed/Activator.java
 
b/examples/karaf-config-example/karaf-config-example-managed/src/main/java/org/apache/karaf/example/config/managed/Activator.java
new file mode 100644
index 0000000000..e6801e36aa
--- /dev/null
+++ 
b/examples/karaf-config-example/karaf-config-example-managed/src/main/java/org/apache/karaf/example/config/managed/Activator.java
@@ -0,0 +1,54 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.karaf.example.config.managed;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.cm.ManagedService;
+
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+public class Activator implements BundleActivator {
+
+    private ServiceRegistration<ManagedService> registration;
+
+    @Override
+    public void start(BundleContext bundleContext) {
+        ManagedService managedService = properties -> {
+            System.out.println("Configuration changed");
+            Enumeration<String> keys = properties.keys();
+            while (keys.hasMoreElements()) {
+                String key = keys.nextElement();
+                System.out.println(key + " = " + properties.get(key));
+            }
+        };
+        Hashtable<String, String> serviceProperties = new Hashtable<>();
+        serviceProperties.put(Constants.SERVICE_PID, 
"org.apache.karaf.example.config");
+        registration = bundleContext.registerService(ManagedService.class, 
managedService, serviceProperties);
+    }
+
+    @Override
+    public void stop(BundleContext bundleContext) {
+        if (registration != null) {
+            registration.unregister();
+        }
+    }
+
+}
diff --git a/examples/karaf-config-example/karaf-config-example-scr/pom.xml 
b/examples/karaf-config-example/karaf-config-example-scr/pom.xml
new file mode 100644
index 0000000000..d81114f4bf
--- /dev/null
+++ b/examples/karaf-config-example/karaf-config-example-scr/pom.xml
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+
+    <!--
+
+        Licensed to the Apache Software Foundation (ASF) under one or more
+        contributor license agreements.  See the NOTICE file distributed with
+        this work for additional information regarding copyright ownership.
+        The ASF licenses this file to You under the Apache License, Version 2.0
+        (the "License"); you may not use this file except in compliance with
+        the License.  You may obtain a copy of the License at
+
+           http://www.apache.org/licenses/LICENSE-2.0
+
+        Unless required by applicable law or agreed to in writing, software
+        distributed under the License is distributed on an "AS IS" BASIS,
+        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
implied.
+        See the License for the specific language governing permissions and
+        limitations under the License.
+    -->
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.karaf.examples</groupId>
+        <artifactId>karaf-config-example</artifactId>
+        <version>4.2.2-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>karaf-config-example-scr</artifactId>
+    <packaging>bundle</packaging>
+    <name>Apache Karaf :: Examples :: Configuration :: SCR</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>osgi.cmpn</artifactId>
+            <version>6.0.0</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
\ No newline at end of file
diff --git 
a/examples/karaf-config-example/karaf-config-example-scr/src/main/java/org/apache/karaf/example/config/scr/MyComponent.java
 
b/examples/karaf-config-example/karaf-config-example-scr/src/main/java/org/apache/karaf/example/config/scr/MyComponent.java
new file mode 100644
index 0000000000..47b50c983c
--- /dev/null
+++ 
b/examples/karaf-config-example/karaf-config-example-scr/src/main/java/org/apache/karaf/example/config/scr/MyComponent.java
@@ -0,0 +1,39 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.karaf.example.config.scr;
+
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+
+import java.util.Dictionary;
+import java.util.Enumeration;
+
+@Component(name = "my-component", immediate = true, configurationPid = 
"org.apache.karaf.example.config")
+public class MyComponent {
+
+    @Activate
+    public void activate(ComponentContext context) {
+        Dictionary<String, Object> properties = context.getProperties();
+        Enumeration<String> keys = properties.keys();
+        while (keys.hasMoreElements()) {
+            String key = keys.nextElement();
+            System.out.println(key + " = " + properties.get(key));
+        }
+    }
+
+}
diff --git a/examples/karaf-config-example/karaf-config-example-static/pom.xml 
b/examples/karaf-config-example/karaf-config-example-static/pom.xml
new file mode 100644
index 0000000000..8821d6362a
--- /dev/null
+++ b/examples/karaf-config-example/karaf-config-example-static/pom.xml
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+
+    <!--
+
+        Licensed to the Apache Software Foundation (ASF) under one or more
+        contributor license agreements.  See the NOTICE file distributed with
+        this work for additional information regarding copyright ownership.
+        The ASF licenses this file to You under the Apache License, Version 2.0
+        (the "License"); you may not use this file except in compliance with
+        the License.  You may obtain a copy of the License at
+
+           http://www.apache.org/licenses/LICENSE-2.0
+
+        Unless required by applicable law or agreed to in writing, software
+        distributed under the License is distributed on an "AS IS" BASIS,
+        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
implied.
+        See the License for the specific language governing permissions and
+        limitations under the License.
+    -->
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.karaf.examples</groupId>
+        <artifactId>karaf-config-example</artifactId>
+        <version>4.2.2-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>karaf-config-example-static</artifactId>
+    <packaging>bundle</packaging>
+    <name>Apache Karaf :: Examples :: Configuration :: Static</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>osgi.core</artifactId>
+            <version>6.0.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>osgi.cmpn</artifactId>
+            <version>6.0.0</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <configuration>
+                    <instructions>
+                        
<Bundle-Activator>org.apache.karaf.example.config.Activator</Bundle-Activator>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
\ No newline at end of file
diff --git 
a/examples/karaf-config-example/karaf-config-example-static/src/main/java/org/apache/karaf/example/config/Activator.java
 
b/examples/karaf-config-example/karaf-config-example-static/src/main/java/org/apache/karaf/example/config/Activator.java
new file mode 100644
index 0000000000..c526906c45
--- /dev/null
+++ 
b/examples/karaf-config-example/karaf-config-example-static/src/main/java/org/apache/karaf/example/config/Activator.java
@@ -0,0 +1,59 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.karaf.example.config;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+import java.util.Dictionary;
+import java.util.Enumeration;
+
+public class Activator implements BundleActivator {
+
+    @Override
+    public void start(BundleContext bundleContext) {
+        ServiceReference<ConfigurationAdmin> reference = 
bundleContext.getServiceReference(ConfigurationAdmin.class);
+        if (reference != null) {
+            // retrieving the ConfigurationAdmin service
+            ConfigurationAdmin configurationAdmin = 
bundleContext.getService(reference);
+            try {
+                // retrieving the configuration using the PID
+                Configuration configuration = 
configurationAdmin.getConfiguration("org.apache.karaf.example.config");
+                if (configuration != null) {
+                    Dictionary<String, Object> properties = 
configuration.getProperties();
+                    Enumeration<String> keys = properties.keys();
+                    while (keys.hasMoreElements()) {
+                        String key = keys.nextElement();
+                        System.out.println(key + " = " + properties.get(key));
+                    }
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+            bundleContext.ungetService(reference);
+        }
+    }
+
+    @Override
+    public void stop(BundleContext bundleContext) {
+        // nothing to do
+    }
+
+}
diff --git a/examples/karaf-config-example/pom.xml 
b/examples/karaf-config-example/pom.xml
new file mode 100644
index 0000000000..f918a22e38
--- /dev/null
+++ b/examples/karaf-config-example/pom.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+
+    <!--
+
+        Licensed to the Apache Software Foundation (ASF) under one or more
+        contributor license agreements.  See the NOTICE file distributed with
+        this work for additional information regarding copyright ownership.
+        The ASF licenses this file to You under the Apache License, Version 2.0
+        (the "License"); you may not use this file except in compliance with
+        the License.  You may obtain a copy of the License at
+
+           http://www.apache.org/licenses/LICENSE-2.0
+
+        Unless required by applicable law or agreed to in writing, software
+        distributed under the License is distributed on an "AS IS" BASIS,
+        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
implied.
+        See the License for the specific language governing permissions and
+        limitations under the License.
+    -->
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.karaf.examples</groupId>
+        <artifactId>apache-karaf-examples</artifactId>
+        <version>4.2.2-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>karaf-config-example</artifactId>
+    <name>Apache Karaf :: Examples :: Configuration</name>
+    <packaging>pom</packaging>
+
+    <modules>
+        <module>karaf-config-example-static</module>
+        <module>karaf-config-example-managed</module>
+        <module>karaf-config-example-managed-factory</module>
+        <module>karaf-config-example-listener</module>
+        <module>karaf-config-example-blueprint</module>
+        <module>karaf-config-example-scr</module>
+        <module>karaf-config-example-features</module>
+    </modules>
+
+</project>
\ No newline at end of file
diff --git a/examples/pom.xml b/examples/pom.xml
index f7cf1a5af8..60fd406187 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -40,6 +40,7 @@
         <module>karaf-camel-example</module>
         <!-- <module>karaf-cdi-example</module> -->
         <module>karaf-command-example</module>
+        <module>karaf-config-example</module>
         <module>karaf-deployer-example</module>
         <module>karaf-dump-example</module>
         <!-- <module>karaf-encryption-example</module> -->
diff --git 
a/itests/test/src/test/java/org/apache/karaf/itests/examples/ConfigExampleTest.java
 
b/itests/test/src/test/java/org/apache/karaf/itests/examples/ConfigExampleTest.java
new file mode 100644
index 0000000000..2fead38ae2
--- /dev/null
+++ 
b/itests/test/src/test/java/org/apache/karaf/itests/examples/ConfigExampleTest.java
@@ -0,0 +1,154 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.karaf.itests.examples;
+
+import org.apache.karaf.itests.KarafTestSupport;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerMethod;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+import javax.inject.Inject;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerMethod.class)
+public class ConfigExampleTest extends KarafTestSupport {
+
+    private ByteArrayOutputStream byteArrayOutputStream = new 
ByteArrayOutputStream();
+    private PrintStream originStream;
+    private PrintStream outStream = new PrintStream(byteArrayOutputStream);
+
+    @Before
+    public void setUp() throws Exception {
+        originStream = System.out;
+        System.setOut(outStream);
+    }
+
+    public void addFeaturesRepository() throws Exception {
+        
addFeaturesRepository("mvn:org.apache.karaf.examples/karaf-config-example-features/"
 + System.getProperty("karaf.version") + "/xml");
+    }
+
+    @Test
+    public void testStatic() throws Exception {
+        addFeaturesRepository();
+
+        installAndAssertFeature("karaf-config-example-static");
+
+        System.out.flush();
+        System.setOut(originStream);
+
+        String output = byteArrayOutputStream.toString();
+
+        System.out.println(output);
+
+        assertContains("foo = bar", output);
+        assertContains("hello = world", output);
+    }
+
+    @Test
+    public void testManaged() throws Exception {
+        addFeaturesRepository();
+
+        installAndAssertFeature("karaf-config-example-managed");
+
+        System.out.flush();
+        assertContains("Configuration changed", 
byteArrayOutputStream.toString());
+
+        Configuration configuration = 
configurationAdmin.getConfiguration("org.apache.karaf.example.config", null);
+        Dictionary<String, Object> properties = configuration.getProperties();
+        if (properties == null) {
+            properties = new Hashtable<>();
+        }
+        properties.put("exam", "test");
+        configuration.update(properties);
+
+        Thread.sleep(500);
+
+        assertContains("exam = test", byteArrayOutputStream.toString());
+    }
+
+    @Test
+    public void testListener() throws Exception {
+        addFeaturesRepository();
+
+        installAndAssertFeature("karaf-config-example-listener");
+
+        Configuration configuration = 
configurationAdmin.getConfiguration("org.apache.karaf.example.config", null);
+        Dictionary<String, Object> properties = new Hashtable<>();
+        properties.put("exam", "test");
+        configuration.update(properties);
+
+        Thread.sleep(500);
+
+        System.out.flush();
+
+        assertContains("Configuration org.apache.karaf.example.config has been 
updated", byteArrayOutputStream.toString());
+    }
+
+    @Test
+    public void testBlueprint() throws Exception {
+        addFeaturesRepository();
+
+        installAndAssertFeature("karaf-config-example-blueprint");
+
+        System.out.flush();
+
+        assertContains("hello = world", byteArrayOutputStream.toString());
+
+        Configuration configuration = 
configurationAdmin.getConfiguration("org.apache.karaf.example.config", null);
+        Dictionary<String, Object> properties = new Hashtable<>();
+        properties.put("hello", "exam");
+        configuration.update(properties);
+
+        Thread.sleep(500);
+
+        System.out.flush();
+
+        assertContains("hello = exam", byteArrayOutputStream.toString());
+    }
+
+    @Test
+    public void testScr() throws Exception {
+        addFeaturesRepository();
+
+        installAndAssertFeature("karaf-config-example-scr");
+
+        System.out.flush();
+
+        assertContainsNot("hello = exam", byteArrayOutputStream.toString());
+
+        Configuration configuration = 
configurationAdmin.getConfiguration("org.apache.karaf.example.config", null);
+        Dictionary<String, Object> properties = new Hashtable<>();
+        properties.put("hello", "exam");
+        configuration.update(properties);
+
+        Thread.sleep(500);
+
+        System.out.flush();
+
+        assertContains("hello = exam", byteArrayOutputStream.toString());
+    }
+
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Add config management exemple
> -----------------------------
>
>                 Key: KARAF-5913
>                 URL: https://issues.apache.org/jira/browse/KARAF-5913
>             Project: Karaf
>          Issue Type: Task
>          Components: karaf
>            Reporter: Jean-Baptiste Onofré
>            Assignee: Jean-Baptiste Onofré
>            Priority: Major
>             Fix For: 4.2.2
>
>
> It would be great to add a new example show how to deal with configuration:
> * static using  {{ConfigurationAdmin}}
> * managed service pure OSGi and via SCR
> * managed service factory pure OSGi and via SCR
> * {{ConfigurationListener}}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to