You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2020/12/02 08:28:01 UTC

[karaf] branch karaf-4.2.x updated: [KARAF-6434] Add CDI example

This is an automated email from the ASF dual-hosted git repository.

jbonofre pushed a commit to branch karaf-4.2.x
in repository https://gitbox.apache.org/repos/asf/karaf.git


The following commit(s) were added to refs/heads/karaf-4.2.x by this push:
     new c93475a  [KARAF-6434] Add CDI example
c93475a is described below

commit c93475a7258b69b178e9821a253455358f9668a8
Author: jbonofre <jb...@apache.org>
AuthorDate: Thu Nov 26 18:42:49 2020 +0100

    [KARAF-6434] Add CDI example
    
    (cherry picked from commit fc1d6afcb2ceee1bafd5336fb77c7a72d78cac8c)
---
 .../features/standard/src/main/feature/feature.xml |  5 +-
 examples/karaf-cdi-example/README.md               | 68 +++++++++++++++
 .../karaf-cdi-example-consumer/pom.xml             | 74 ++++++++++++++++
 .../examples/cdi/consumer/MyConsumerBean.java      | 37 ++++++++
 .../karaf-cdi-example-features/pom.xml             | 99 ++++++++++++++++++++++
 .../src/main/feature/feature.xml                   | 33 ++++++++
 .../karaf-cdi-example-provider/pom.xml             | 69 +++++++++++++++
 .../karaf/examples/cdi/provider/MyServiceBean.java | 30 +++++++
 examples/karaf-cdi-example/pom.xml                 | 41 +++++++++
 examples/pom.xml                                   |  2 +-
 .../karaf/itests/examples/CdiExampleTest.java      | 41 +++++++++
 11 files changed, 496 insertions(+), 3 deletions(-)

diff --git a/assemblies/features/standard/src/main/feature/feature.xml b/assemblies/features/standard/src/main/feature/feature.xml
index b5104ca..414be32 100644
--- a/assemblies/features/standard/src/main/feature/feature.xml
+++ b/assemblies/features/standard/src/main/feature/feature.xml
@@ -112,6 +112,7 @@ pax-wicket=mvn:org.ops4j.pax.wicket/pax-wicket-features/RELEASE/xml/features
 ecf=http://download.eclipse.org/rt/ecf/RELEASE/site.p2/karaf-features.xml
 decanter=mvn:org.apache.karaf.decanter/apache-karaf-decanter/RELEASE/xml/features
 eclipsesource-jaxrs=mvn:com.eclipsesource.jaxrs/features/RELEASE/xml/features
+aries-cdi=mvn:org.apache.aries.cdi/aries-cdi-feature/RELEASE/xml/features
 aries-jpa=mvn:org.apache.aries.jpa/jpa-features/RELEASE/xml/features
 aries-rsa=mvn:org.apache.aries.rsa/rsa-features/RELEASE/xml/features
 hibernate=mvn:org.hibernate/hibernate-osgi/RELEASE/xml/karaf
@@ -1478,8 +1479,8 @@ org.apache.felix.eventadmin.AddSubject=${env:ORG_APACHE_FELIX_EVENTADMIN_IMPL_EV
     </feature>
 
     <feature name="scr" description="Declarative Service support" version="${project.version}">
-        <bundle dependency="true" start-level="30">mvn:org.osgi/org.osgi.util.function/1.0.0</bundle>
-        <bundle dependency="true" start-level="30">mvn:org.osgi/org.osgi.util.promise/1.0.0</bundle>
+        <bundle dependency="true" start-level="30">mvn:org.osgi/org.osgi.util.function/1.1.0</bundle>
+        <bundle dependency="true" start-level="30">mvn:org.osgi/org.osgi.util.promise/1.1.0</bundle>
         <bundle dependency="true" start-level="30">mvn:org.apache.felix/org.apache.felix.metatype/${felix.metatype.version}</bundle>
         <bundle start-level="30">mvn:org.apache.felix/org.apache.felix.scr/${felix.scr.version}</bundle>
         <conditional>
diff --git a/examples/karaf-cdi-example/README.md b/examples/karaf-cdi-example/README.md
new file mode 100644
index 0000000..35b7f90
--- /dev/null
+++ b/examples/karaf-cdi-example/README.md
@@ -0,0 +1,68 @@
+<!--
+    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 CDI Example
+
+## Abstract
+
+It's possible to use CDI in your applications, including sharing bean between bundles using the Karaf service registry.
+
+In addition of supporting the regular CDI annotations (`@ApplicationScoped`, `@Inject`, etc), Karaf CDI also supports
+couple of new OSGi CDI annotations: `@Service` and `@Reference`.
+
+In this example, we are using Aries CDI and OpenWebBeans as CDI container.
+
+## Artifacts
+
+* `karaf-cdi-example-provider` provides an application scope bean and using the `@Service` annotation to register the bean in the Karaf service registry (can be used in another bundle).
+* `karaf-cdi-example-consumer` creates another bean and inject the provider bean from the registry (thanks to the `@Reference` annotation).
+* `karaf-cdi-example-features` provides a Karaf features XML to easily install the example application.
+
+##Build 
+
+Simply use:
+
+```
+mvn clean install
+```
+
+##Feature and Deployment
+
+On a running Karaf instance, you register the CDI example features repository with:
+
+```
+karaf@root()> feature:repo-add mvn:org.apache.karaf.examples/karaf-cdi-example-features/LATEST/xml
+```
+
+Then you can install the `karaf-cdi-example-provider` feature:
+
+```
+karaf@root()> feature:install karaf-cdi-example-provider
+```
+
+Then, you can install the `karaf-cdi-example-consumer` feature:
+
+```
+karaf@root()> feature:install karaf-cdi-example-consumer
+```
+
+When you install the consumer feature, you will see:
+
+```
+Hello world
+```
\ No newline at end of file
diff --git a/examples/karaf-cdi-example/karaf-cdi-example-consumer/pom.xml b/examples/karaf-cdi-example/karaf-cdi-example-consumer/pom.xml
new file mode 100644
index 0000000..acad1ae
--- /dev/null
+++ b/examples/karaf-cdi-example/karaf-cdi-example-consumer/pom.xml
@@ -0,0 +1,74 @@
+<?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-cdi-example</artifactId>
+        <version>4.2.11-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>karaf-cdi-example-consumer</artifactId>
+    <name>Apache Karaf :: Examples :: CDI :: Consumer</name>
+    <packaging>bundle</packaging>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.karaf.examples</groupId>
+            <artifactId>karaf-cdi-example-provider</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.service.cdi</artifactId>
+            <version>1.0.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-atinject_1.0_spec</artifactId>
+            <version>1.2</version>
+        </dependency>
+        <dependency>
+            <groupId>jakarta.enterprise</groupId>
+            <artifactId>jakarta.enterprise.cdi-api</artifactId>
+            <version>2.0.2</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <!-- Waiting https://issues.apache.org/jira/browse/FELIX-6337 -->
+                <version>4.2.1</version>
+                <configuration>
+                    <instructions>
+                        <_cdiannotations>*;discover=annotated</_cdiannotations>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
diff --git a/examples/karaf-cdi-example/karaf-cdi-example-consumer/src/main/java/org/apache/karaf/examples/cdi/consumer/MyConsumerBean.java b/examples/karaf-cdi-example/karaf-cdi-example-consumer/src/main/java/org/apache/karaf/examples/cdi/consumer/MyConsumerBean.java
new file mode 100644
index 0000000..c8ef478
--- /dev/null
+++ b/examples/karaf-cdi-example/karaf-cdi-example-consumer/src/main/java/org/apache/karaf/examples/cdi/consumer/MyConsumerBean.java
@@ -0,0 +1,37 @@
+/*
+ * 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.examples.cdi.consumer;
+
+import org.apache.karaf.examples.cdi.provider.MyServiceBean;
+import org.osgi.service.cdi.annotations.Reference;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.context.Initialized;
+import javax.enterprise.event.Observes;
+import javax.inject.Inject;
+
+@ApplicationScoped
+public class MyConsumerBean {
+
+    @Reference
+    @Inject
+    private MyServiceBean service;
+
+    public void onStart(@Observes @Initialized(ApplicationScoped.class) Object start) {
+        System.out.println(service.greeting("world"));
+    }
+
+}
diff --git a/examples/karaf-cdi-example/karaf-cdi-example-features/pom.xml b/examples/karaf-cdi-example/karaf-cdi-example-features/pom.xml
new file mode 100644
index 0000000..dfd68c4
--- /dev/null
+++ b/examples/karaf-cdi-example/karaf-cdi-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-cdi-example</artifactId>
+        <version>4.2.11-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>karaf-cdi-example-features</artifactId>
+    <packaging>pom</packaging>
+    <name>Apache Karaf :: Examples :: CDI :: 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>
diff --git a/examples/karaf-cdi-example/karaf-cdi-example-features/src/main/feature/feature.xml b/examples/karaf-cdi-example/karaf-cdi-example-features/src/main/feature/feature.xml
new file mode 100644
index 0000000..e7fbbbb
--- /dev/null
+++ b/examples/karaf-cdi-example/karaf-cdi-example-features/src/main/feature/feature.xml
@@ -0,0 +1,33 @@
+<?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-cdi-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">
+
+    <repository>mvn:org.apache.aries.cdi/aries-cdi-feature/1.1.3/xml/features</repository>
+
+    <feature name="karaf-cdi-example-provider" version="${project.version}">
+        <feature prerequisite="true">osgi-cdi-owb</feature>
+        <bundle>mvn:org.apache.karaf.examples/karaf-cdi-example-provider/${project.version}</bundle>
+    </feature>
+
+    <feature name="karaf-cdi-example-consumer" version="${project.version}">
+        <feature prerequisite="true">karaf-cdi-example-provider</feature>
+        <bundle>mvn:org.apache.karaf.examples/karaf-cdi-example-consumer/${project.version}</bundle>
+    </feature>
+
+</features>
diff --git a/examples/karaf-cdi-example/karaf-cdi-example-provider/pom.xml b/examples/karaf-cdi-example/karaf-cdi-example-provider/pom.xml
new file mode 100644
index 0000000..b6633e3
--- /dev/null
+++ b/examples/karaf-cdi-example/karaf-cdi-example-provider/pom.xml
@@ -0,0 +1,69 @@
+<?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-cdi-example</artifactId>
+        <version>4.2.11-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>karaf-cdi-example-provider</artifactId>
+    <name>Apache Karaf :: Examples :: CDI :: Provider</name>
+    <packaging>bundle</packaging>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.service.cdi</artifactId>
+            <version>1.0.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-atinject_1.0_spec</artifactId>
+            <version>1.2</version>
+        </dependency>
+        <dependency>
+            <groupId>jakarta.enterprise</groupId>
+            <artifactId>jakarta.enterprise.cdi-api</artifactId>
+            <version>2.0.2</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <!-- Waiting https://issues.apache.org/jira/browse/FELIX-6337 -->
+                <version>4.2.1</version>
+                <configuration>
+                    <instructions>
+                        <_cdiannotations>*;discover=annotated</_cdiannotations>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
diff --git a/examples/karaf-cdi-example/karaf-cdi-example-provider/src/main/java/org/apache/karaf/examples/cdi/provider/MyServiceBean.java b/examples/karaf-cdi-example/karaf-cdi-example-provider/src/main/java/org/apache/karaf/examples/cdi/provider/MyServiceBean.java
new file mode 100644
index 0000000..8a5b141
--- /dev/null
+++ b/examples/karaf-cdi-example/karaf-cdi-example-provider/src/main/java/org/apache/karaf/examples/cdi/provider/MyServiceBean.java
@@ -0,0 +1,30 @@
+/*
+ * 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.examples.cdi.provider;
+
+import org.osgi.service.cdi.annotations.Service;
+
+import javax.enterprise.context.ApplicationScoped;
+
+@Service
+@ApplicationScoped
+public class MyServiceBean {
+
+    public String greeting(String message) {
+        return "Hello " + message;
+    }
+
+}
diff --git a/examples/karaf-cdi-example/pom.xml b/examples/karaf-cdi-example/pom.xml
new file mode 100644
index 0000000..75f35d2
--- /dev/null
+++ b/examples/karaf-cdi-example/pom.xml
@@ -0,0 +1,41 @@
+<?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.11-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>karaf-cdi-example</artifactId>
+    <name>Apache Karaf :: Examples :: CDI</name>
+    <packaging>pom</packaging>
+
+    <modules>
+        <module>karaf-cdi-example-provider</module>
+        <module>karaf-cdi-example-consumer</module>
+        <module>karaf-cdi-example-features</module>
+    </modules>
+
+</project>
diff --git a/examples/pom.xml b/examples/pom.xml
index 427fa1a..d41455f 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -38,7 +38,7 @@
         <module>karaf-branding-example</module>
         <module>karaf-bundle-example</module>
         <module>karaf-camel-example</module>
-        <!-- <module>karaf-cdi-example</module> -->
+        <module>karaf-cdi-example</module>
         <module>karaf-command-example</module>
         <module>karaf-config-example</module>
         <module>karaf-deployer-example</module>
diff --git a/itests/test/src/test/java/org/apache/karaf/itests/examples/CdiExampleTest.java b/itests/test/src/test/java/org/apache/karaf/itests/examples/CdiExampleTest.java
new file mode 100644
index 0000000..9493b0b
--- /dev/null
+++ b/itests/test/src/test/java/org/apache/karaf/itests/examples/CdiExampleTest.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed 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.BaseTest;
+import org.junit.Assert;
+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.PerClass;
+
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class CdiExampleTest extends BaseTest {
+
+    @Test
+    public void test() throws Exception {
+        addFeaturesRepository("mvn:org.apache.karaf.examples/karaf-cdi-example-features/" + System.getProperty("karaf.version") + "/xml");
+
+        installAndAssertFeature("karaf-cdi-example-provider");
+
+        Object object = getOsgiService("org.apache.karaf.examples.cdi.provider.MyServiceBean");
+
+        Assert.assertNotNull(object);
+
+        installAndAssertFeature("karaf-cdi-example-consumer");
+    }
+
+}