{"id":13627,"date":"2013-06-04T22:00:15","date_gmt":"2013-06-04T19:00:15","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=13627"},"modified":"2019-12-09T21:14:18","modified_gmt":"2019-12-09T19:14:18","slug":"java-ee-cdi-dependency-disambiguation-example","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2013\/06\/java-ee-cdi-dependency-disambiguation-example.html","title":{"rendered":"Java EE CDI dependency disambiguation example"},"content":{"rendered":"<p>In this tutorial we shall show you how to avoid dependency disambiguation in CDI beans. In CDI we can achieve dependency injection for multiple implementations of an interface to different clients in an application. The problem of dependency disambiguation is how a client can call a specific implementation among different ones, without any errors occurring.<\/p>\n<p>To see how we can avoid dependency disambiguation when injecting beans to an application we will create a simple service. We will create two implementations of the service and then we will inject both implementations in a servlet in our application. We will make use of the <code>@Qualifiers<\/code>, as will be explained below.<\/p>\n<p>Our preferred development environment is <a href=\"http:\/\/www.eclipse.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">Eclipse<\/a>. We are using Eclipse Juno (4.2) version, along with <a href=\"http:\/\/maven.apache.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">Maven<\/a> Integration plugin version 3.1.0. You can download Eclipse from <a href=\"http:\/\/www.eclipse.org\/downloads\/\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a> and Maven Plugin for Eclipse from <a href=\"http:\/\/maven.apache.org\/eclipse-plugin.html\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>. The installation of Maven plugin for Eclipse is out of the scope of this tutorial and will not be discussed. <a href=\"http:\/\/tomcat.apache.org\/download-70.cgi\" target=\"_blank\" rel=\"noopener noreferrer\">Tomcat 7<\/a> is the application server used.<\/p>\n<p>Let&#8217;s begin,<\/p>\n<h2>1. Create a new Maven project<\/h2>\n<p>Go to File -&gt; Project -&gt;Maven -&gt; Maven Project.<\/p>\n<p><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/06\/New-Maven-Project.png\"><img decoding=\"async\" class=\"alignnone size-medium wp-image-4341\" alt=\"New-Maven-Project\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/06\/New-Maven-Project.png\"><\/a><\/p>\n<p>In the &#8220;Select project name and location&#8221; page of the wizard, make sure that &#8220;Create a simple project (skip archetype selection)&#8221; option is <strong>unchecked<\/strong>, hit &#8220;Next&#8221; to continue with default values.<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/07\/new-project.png\"><img decoding=\"async\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/07\/new-project.png\" alt=\"new project\" width=\"602\" height=\"547\" class=\"alignnone size-full wp-image-18290\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/07\/new-project.png 602w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/07\/new-project-300x272.png 300w\" sizes=\"(max-width: 602px) 100vw, 602px\" \/><\/a><\/p>\n<p>Here the maven archetype for creating a web application must be added. Click on <strong>&#8220;Add Archetype&#8221;<\/strong> and add the archetype. Set the &#8220;Archetype Group Id&#8221; variable to <code>\"org.apache.maven.archetypes\"<\/code>, the &#8220;Archetype artifact Id&#8221; variable to <code>\"maven-archetype-webapp\"<\/code> and the &#8220;Archetype Version&#8221; to <code>\"1.0\"<\/code>. Click on <strong>&#8220;OK&#8221;<\/strong> to continue.<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/07\/maven-archetype-webapp.png\"><img decoding=\"async\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/07\/maven-archetype-webapp.png\" alt=\"maven-archetype-webapp\" width=\"660\" height=\"549\" class=\"alignnone size-full wp-image-18291\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/07\/maven-archetype-webapp.png 660w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/07\/maven-archetype-webapp-300x249.png 300w\" sizes=\"(max-width: 660px) 100vw, 660px\" \/><\/a><\/p>\n<p>In the &#8220;Enter an artifact id&#8221; page of the wizard, you can define the name and main package of your project. Set the &#8220;Group Id&#8221; variable to <code>\"com.javacodegeeks.snippets.enterprise\"<\/code> and the &#8220;Artifact Id&#8221; variable to <code>\"cdibeans\"<\/code>. The aforementioned selections compose the main project package as <code>\"com.javacodegeeks.snippets.enterprise.cdibeans\"<\/code> and the project name as <code>\"cdibeans\"<\/code>. Set the &#8220;Package&#8221; variable to <code>\"war\"<\/code>, so that a war file will be created to be deployed to tomcat server. Hit &#8220;Finish&#8221; to exit the wizard and to create your project.<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/04\/newcdiproject1.png\"><img decoding=\"async\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/04\/newcdiproject1.png\" alt=\"newcdiproject1\" width=\"602\" height=\"542\" class=\"alignnone size-full wp-image-18913\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/04\/newcdiproject1.png 602w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/04\/newcdiproject1-300x270.png 300w\" sizes=\"(max-width: 602px) 100vw, 602px\" \/><\/a><div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>The Maven project structure is shown below:<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/04\/newcdiproject2.png\"><img decoding=\"async\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/04\/newcdiproject2.png\" alt=\"newcdiproject2\" width=\"369\" height=\"396\" class=\"alignnone size-full wp-image-18914\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/04\/newcdiproject2.png 369w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/04\/newcdiproject2-279x300.png 279w\" sizes=\"(max-width: 369px) 100vw, 369px\" \/><\/a><\/p>\n<ul>It consists of the following folders:<\/p>\n<li>\/src\/main\/java folder, that contains source files for the dynamic content of the application,<\/li>\n<li>\/src\/test\/java folder contains all source files for unit tests,<\/li>\n<li>\/src\/main\/resources folder contains configurations files,<\/li>\n<li>\/target folder contains the compiled and packaged deliverables,<\/li>\n<li>\/src\/main\/resources\/webapp\/WEB-INF folder contains the deployment descriptors for the Web application ,<\/li>\n<li>the pom.xml is the project object model (POM) file. The single file that contains all project related configuration.<\/li>\n<\/ul>\n<h2>2. Add all the necessary dependencies<\/h2>\n<p>You can add the dependencies in Maven\u2019s <code>pom.xml<\/code> file, by editing it at the &#8220;Pom.xml&#8221; page of the POM editor, as shown below:<br \/>\n&nbsp;<br \/>\n<span style=\"text-decoration: underline;\"><em>pom.xml:<\/em><\/span><\/p>\n<pre class=\"brush:xml\">&lt;project xmlns=\"http:\/\/maven.apache.org\/POM\/4.0.0\" xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\n\txsi:schemaLocation=\"http:\/\/maven.apache.org\/POM\/4.0.0 http:\/\/maven.apache.org\/maven-v4_0_0.xsd\"&gt;\n\t&lt;modelVersion&gt;4.0.0&lt;\/modelVersion&gt;\n\t&lt;groupId&gt;com.javacodegeeks.snippets.enterprise.cdi&lt;\/groupId&gt;\n\t&lt;artifactId&gt;cdibeans&lt;\/artifactId&gt;\n\t&lt;packaging&gt;war&lt;\/packaging&gt;\n\t&lt;version&gt;0.0.1-SNAPSHOT&lt;\/version&gt;\n\t&lt;name&gt;cdibeans Maven Webapp&lt;\/name&gt;\n\t&lt;url&gt;http:\/\/maven.apache.org&lt;\/url&gt;\n\t&lt;dependencies&gt;\n\t\t&lt;dependency&gt;\n\t\t\t&lt;groupId&gt;org.jboss.weld.servlet&lt;\/groupId&gt;\n\t\t\t&lt;artifactId&gt;weld-servlet&lt;\/artifactId&gt;\n\t\t\t&lt;version&gt;1.1.10.Final&lt;\/version&gt;\n\t\t&lt;\/dependency&gt;\n\t\t&lt;dependency&gt;\n\t\t\t&lt;groupId&gt;javax.servlet&lt;\/groupId&gt;\n\t\t\t&lt;artifactId&gt;jstl&lt;\/artifactId&gt;\n\t\t\t&lt;version&gt;1.2&lt;\/version&gt;\n\t\t&lt;\/dependency&gt;\n\t\t&lt;dependency&gt;\n\t\t\t&lt;groupId&gt;javax.servlet&lt;\/groupId&gt;\n\t\t\t&lt;artifactId&gt;javax.servlet-api&lt;\/artifactId&gt;\n\t\t\t&lt;version&gt;3.0.1&lt;\/version&gt;\n\t\t\t&lt;scope&gt;provided&lt;\/scope&gt;\n\t\t&lt;\/dependency&gt;\n\t\t&lt;dependency&gt;\n\t\t\t&lt;groupId&gt;org.glassfish&lt;\/groupId&gt;\n\t\t\t&lt;artifactId&gt;javax.faces&lt;\/artifactId&gt;\n\t\t\t&lt;version&gt;2.1.7&lt;\/version&gt;\n\t\t&lt;\/dependency&gt;\n\t&lt;\/dependencies&gt;\n\n\t&lt;build&gt;\n\t\t&lt;finalName&gt;cdibeans&lt;\/finalName&gt;\n\t&lt;\/build&gt;\n&lt;\/project&gt;\n<\/pre>\n<p>As you can see Maven manages library dependencies declaratively. A local repository is created (by default under {user_home}\/.m2 folder) and all required libraries are downloaded and placed there from public repositories. Furthermore intra \u2013 library dependencies are automatically resolved and manipulated.<\/p>\n<h2>3. Create a simple Service<\/h2>\n<p>We make use of a simple service that creates a greeting message for the application that uses it. The <code>GreetingCard.java<\/code> class is an interface with a method that produces the greeting message.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>GreetingCard.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.snippets.enterprise.cdibeans;\n\npublic interface GreetingCard {\n\n\tvoid sayHello();\n}\n<\/pre>\n<p>We create two implementations of the service. Each implementation produces a different message, as shown below:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>GreetingCardImpl.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.snippets.enterprise.cdibeans.impl;\n\nimport com.javacodegeeks.snippets.enterprise.cdibeans.GreetingCard;\n\npublic class GreetingCardImpl implements GreetingCard {\n\n\tpublic void sayHello() {\n\t\tSystem.out.println(\"Hello!!!\");\n\t}\n\n}\n<\/pre>\n<p><span style=\"text-decoration: underline;\"><em>AnotherGreetingCardImpl.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.snippets.enterprise.cdibeans.impl;\n\nimport com.javacodegeeks.snippets.enterprise.cdibeans.GreetingCard;\n\n\npublic class AnotherGreetingCardImpl implements GreetingCard {\n\n\tpublic void sayHello() {\n\t\tSystem.out.println(\"Have a nice day!!!\");\n\t}\n\n}\n<\/pre>\n<h2>4. Use of the Service<\/h2>\n<p>In order to inject the service to another bean, we can make use of the <code>@Qualifier<\/code>. CDI allows us to create our own Java annotation, and then use it in the injection point of our application to get the correct implementation of the <code>GreetingCard<\/code> according to the <code>GreetingType<\/code> of the bean.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Greetings.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.snippets.enterprise.cdibeans;\n\nimport static java.lang.annotation.ElementType.FIELD;\nimport static java.lang.annotation.ElementType.TYPE;\nimport static java.lang.annotation.ElementType.METHOD;\nimport static java.lang.annotation.RetentionPolicy.RUNTIME;\nimport java.lang.annotation.Retention;\nimport java.lang.annotation.Target;\n\nimport javax.inject.Qualifier;\n\n@Qualifier\n@Retention(RUNTIME)\n@Target({ FIELD, TYPE, METHOD })\npublic @interface Greetings {\n\n\tGreetingType value();\n\n}\n<\/pre>\n<p>The <code>GreetingType.java<\/code> is an enumeration, as shown below:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>GreetingType.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.snippets.enterprise.cdibeans;\n\npublic enum GreetingType {\n\n\tHELLO, HI;\n}\n<\/pre>\n<p>Now, the service implementations use the annotation, as shown below:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>GreetingCardImpl.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.snippets.enterprise.cdibeans.impl;\n\nimport com.javacodegeeks.snippets.enterprise.cdibeans.GreetingCard;\n\n@Greetings(GreetingType.HELLO)\npublic class GreetingCardImpl implements GreetingCard {\n\n\tpublic void sayHello() {\n\t\tSystem.out.println(\"Hello!!!\");\n\t}\n\n}\n<\/pre>\n<p><span style=\"text-decoration: underline;\"><em>AnotherGreetingCardImpl.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.snippets.enterprise.cdibeans.impl;\n\nimport com.javacodegeeks.snippets.enterprise.cdibeans.GreetingCard;\n\n@Greetings(GreetingType.HI)\npublic class AnotherGreetingCardImpl implements GreetingCard {\n\n\tpublic void sayHello() {\n\t\tSystem.out.println(\"Have a nice day!!!\");\n\t}\n\n}\n<\/pre>\n<h2>5. Inject the service in a servlet<\/h2>\n<p>We create a simple servlet, and inject both implementations of the service, using the <code>@Inject<\/code> annotation provided by CDI, as shown below:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>GreetingServlet.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.snippets.enterprise.cdibeans.servlet;\n\nimport java.io.IOException;\nimport java.io.PrintWriter;\n\nimport javax.inject.Inject;\nimport javax.servlet.ServletException;\nimport javax.servlet.annotation.WebServlet;\nimport javax.servlet.http.HttpServlet;\nimport javax.servlet.http.HttpServletRequest;\nimport javax.servlet.http.HttpServletResponse;\n\nimport com.javacodegeeks.snippets.enterprise.cdibeans.GreetingCard;\nimport com.javacodegeeks.snippets.enterprise.cdibeans.GreetingType;\nimport com.javacodegeeks.snippets.enterprise.cdibeans.Greetings;\n\n@WebServlet(name = \"greetingServlet\", urlPatterns = {\"\/sayHello\"})\npublic class GreetingServlet extends HttpServlet {\n\n\tprivate static final long serialVersionUID = 2280890757609124481L;\n\t\n\t@Inject\n\t@Greetings(GreetingType.HELLO)\n\tprivate GreetingCard greetingCard;\n\n\t@Inject\n\t@Greetings(GreetingType.HI)\n\tprivate GreetingCard anotherGreetingCard;\n\n\t  public void init() throws ServletException {\n\t  }\n\n\t  public void doGet(HttpServletRequest request, HttpServletResponse response)\n\t            throws ServletException, IOException {\n\t      response.setContentType(\"text\/html\");\n\t      PrintWriter out = response.getWriter();\n\t      out.println(\"&lt;h1&gt;\" + greetingCard.sayHello() + \"&lt;\/h1&gt;\");\n\t      out.println(\"&lt;h1&gt;\" + anotherGreetingCard.sayHello() + \"&lt;\/h1&gt;\");\n\t  }\n\t  \n\t  public void destroy(){\n\t  }\n\n}\n<\/pre>\n<p>To run the example we must build the project with Maven, and then place the <code>war<\/code> file produced in <code>webbaps<\/code> folder of tomcat. Then, we can hit on :<\/p>\n<p><code>http:\/\/localhost\/8080\/cdibeans\/sayHello<\/code><\/p>\n<p>and the result is the one shown below:<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/04\/prod.png\"><img decoding=\"async\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/04\/prod.png\" alt=\"prod\" width=\"531\" height=\"416\" class=\"alignnone size-full wp-image-19094\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/04\/prod.png 531w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/04\/prod-300x235.png 300w\" sizes=\"(max-width: 531px) 100vw, 531px\" \/><\/a><\/p>\n<p>Note that dependency disambiguation may also occur when using <code>Producer<\/code> methods to inject CDI beans, as shown in the <a href=\"http:\/\/www.javacodegeeks.com\/2013\/04\/java-ee-cdi-producer-methods-tutorial.html\" target=\"_blank\" rel=\"noopener noreferrer\">Java EE CDI Producer methods tutorial<\/a>.<br \/>\n&nbsp;<br \/>\nThis was a tutorial of Java EE CDI dependency disambiguation.<br \/>\n&nbsp;<br \/>\nDownload the source code of this tutorial: <a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/06\/CDIDependencyDisambiguationExample.zip\">CDIDependencyDisambiguationExample.zip<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial we shall show you how to avoid dependency disambiguation in CDI beans. In CDI we can achieve dependency injection for multiple implementations of an interface to different clients in an application. The problem of dependency disambiguation is how a client can call a specific implementation among different ones, without any errors occurring. &hellip;<\/p>\n","protected":false},"author":472,"featured_media":148,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[290,289],"class_list":["post-13627","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-cdi","tag-java-ee6"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Java EE CDI dependency disambiguation example<\/title>\n<meta name=\"description\" content=\"In this tutorial we shall show you how to avoid dependency disambiguation in CDI beans. In CDI we can achieve dependency injection for multiple\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2013\/06\/java-ee-cdi-dependency-disambiguation-example.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java EE CDI dependency disambiguation example\" \/>\n<meta property=\"og:description\" content=\"In this tutorial we shall show you how to avoid dependency disambiguation in CDI beans. In CDI we can achieve dependency injection for multiple\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2013\/06\/java-ee-cdi-dependency-disambiguation-example.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2013-06-04T19:00:15+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-12-09T19:14:18+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Theodora Fragkouli\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Theodora Fragkouli\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/06\\\/java-ee-cdi-dependency-disambiguation-example.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/06\\\/java-ee-cdi-dependency-disambiguation-example.html\"},\"author\":{\"name\":\"Theodora Fragkouli\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/6bdf5e6534337198ce06de139e9b617b\"},\"headline\":\"Java EE CDI dependency disambiguation example\",\"datePublished\":\"2013-06-04T19:00:15+00:00\",\"dateModified\":\"2019-12-09T19:14:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/06\\\/java-ee-cdi-dependency-disambiguation-example.html\"},\"wordCount\":745,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/06\\\/java-ee-cdi-dependency-disambiguation-example.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/java-logo.jpg\",\"keywords\":[\"CDI\",\"Java EE6\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/06\\\/java-ee-cdi-dependency-disambiguation-example.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/06\\\/java-ee-cdi-dependency-disambiguation-example.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/06\\\/java-ee-cdi-dependency-disambiguation-example.html\",\"name\":\"Java EE CDI dependency disambiguation example\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/06\\\/java-ee-cdi-dependency-disambiguation-example.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/06\\\/java-ee-cdi-dependency-disambiguation-example.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/java-logo.jpg\",\"datePublished\":\"2013-06-04T19:00:15+00:00\",\"dateModified\":\"2019-12-09T19:14:18+00:00\",\"description\":\"In this tutorial we shall show you how to avoid dependency disambiguation in CDI beans. In CDI we can achieve dependency injection for multiple\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/06\\\/java-ee-cdi-dependency-disambiguation-example.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/06\\\/java-ee-cdi-dependency-disambiguation-example.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/06\\\/java-ee-cdi-dependency-disambiguation-example.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/java-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/java-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/06\\\/java-ee-cdi-dependency-disambiguation-example.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Java EE CDI dependency disambiguation example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/6bdf5e6534337198ce06de139e9b617b\",\"name\":\"Theodora Fragkouli\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/50acde9ff30ae7c7473f7581747f7cdc58aa0156e56bf0a578adaa59ca93ae73?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/50acde9ff30ae7c7473f7581747f7cdc58aa0156e56bf0a578adaa59ca93ae73?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/50acde9ff30ae7c7473f7581747f7cdc58aa0156e56bf0a578adaa59ca93ae73?s=96&d=mm&r=g\",\"caption\":\"Theodora Fragkouli\"},\"description\":\"Theodora has graduated from Computer Engineering and Informatics Department in the University of Patras. She also holds a Master degree in Economics from the National and Technical University of Athens. During her studies she has been involved with a large number of projects ranging from programming and software engineering to telecommunications, hardware design and analysis. She works as a junior Software Engineer in the telecommunications sector where she is mainly involved with projects based on Java and Big Data technologies.\",\"sameAs\":[\"http:\\\/\\\/www.javacodegeeks.com\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/theodora-fragkouli\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java EE CDI dependency disambiguation example","description":"In this tutorial we shall show you how to avoid dependency disambiguation in CDI beans. In CDI we can achieve dependency injection for multiple","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2013\/06\/java-ee-cdi-dependency-disambiguation-example.html","og_locale":"en_US","og_type":"article","og_title":"Java EE CDI dependency disambiguation example","og_description":"In this tutorial we shall show you how to avoid dependency disambiguation in CDI beans. In CDI we can achieve dependency injection for multiple","og_url":"https:\/\/www.javacodegeeks.com\/2013\/06\/java-ee-cdi-dependency-disambiguation-example.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2013-06-04T19:00:15+00:00","article_modified_time":"2019-12-09T19:14:18+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","type":"image\/jpeg"}],"author":"Theodora Fragkouli","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Theodora Fragkouli","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2013\/06\/java-ee-cdi-dependency-disambiguation-example.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/06\/java-ee-cdi-dependency-disambiguation-example.html"},"author":{"name":"Theodora Fragkouli","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/6bdf5e6534337198ce06de139e9b617b"},"headline":"Java EE CDI dependency disambiguation example","datePublished":"2013-06-04T19:00:15+00:00","dateModified":"2019-12-09T19:14:18+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/06\/java-ee-cdi-dependency-disambiguation-example.html"},"wordCount":745,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/06\/java-ee-cdi-dependency-disambiguation-example.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","keywords":["CDI","Java EE6"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2013\/06\/java-ee-cdi-dependency-disambiguation-example.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2013\/06\/java-ee-cdi-dependency-disambiguation-example.html","url":"https:\/\/www.javacodegeeks.com\/2013\/06\/java-ee-cdi-dependency-disambiguation-example.html","name":"Java EE CDI dependency disambiguation example","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/06\/java-ee-cdi-dependency-disambiguation-example.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/06\/java-ee-cdi-dependency-disambiguation-example.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","datePublished":"2013-06-04T19:00:15+00:00","dateModified":"2019-12-09T19:14:18+00:00","description":"In this tutorial we shall show you how to avoid dependency disambiguation in CDI beans. In CDI we can achieve dependency injection for multiple","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/06\/java-ee-cdi-dependency-disambiguation-example.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2013\/06\/java-ee-cdi-dependency-disambiguation-example.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2013\/06\/java-ee-cdi-dependency-disambiguation-example.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2013\/06\/java-ee-cdi-dependency-disambiguation-example.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Java EE CDI dependency disambiguation example"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/6bdf5e6534337198ce06de139e9b617b","name":"Theodora Fragkouli","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/50acde9ff30ae7c7473f7581747f7cdc58aa0156e56bf0a578adaa59ca93ae73?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/50acde9ff30ae7c7473f7581747f7cdc58aa0156e56bf0a578adaa59ca93ae73?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/50acde9ff30ae7c7473f7581747f7cdc58aa0156e56bf0a578adaa59ca93ae73?s=96&d=mm&r=g","caption":"Theodora Fragkouli"},"description":"Theodora has graduated from Computer Engineering and Informatics Department in the University of Patras. She also holds a Master degree in Economics from the National and Technical University of Athens. During her studies she has been involved with a large number of projects ranging from programming and software engineering to telecommunications, hardware design and analysis. She works as a junior Software Engineer in the telecommunications sector where she is mainly involved with projects based on Java and Big Data technologies.","sameAs":["http:\/\/www.javacodegeeks.com\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/theodora-fragkouli"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/13627","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/472"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=13627"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/13627\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/148"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=13627"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=13627"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=13627"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}