{"id":12519,"date":"2013-05-08T19:19:35","date_gmt":"2013-05-08T16:19:35","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=12519"},"modified":"2019-12-09T21:39:40","modified_gmt":"2019-12-09T19:39:40","slug":"java-ee-cdi-disposer-methods-example","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2013\/05\/java-ee-cdi-disposer-methods-example.html","title":{"rendered":"Java EE CDI Disposer methods example"},"content":{"rendered":"<p>This is a tutorial of CDI <code>Disposer<\/code> methods. In CDI, since a <code>Producer<\/code> method generates an object that can then be injected in an application, the <code>Disposer<\/code> method is used so that the object is removed when its work is completed. A <code>Disposer<\/code> method is always matched to a <code>Producer<\/code> method.<\/p>\n<p>An example of the <code>Disposer<\/code> method use is when an application uses a connection to a database. Since the connection must close after the interface with the database is completed, the <code>Disposer<\/code> method is used to remove the object that represents the connection.<\/p>\n<p>Here we shall show you how to make use of a <code>Disposer<\/code> method. We will create a simple service. Then we will create a <code>Producer<\/code> method to produce and inject the service in an application and a <code>Disposer<\/code> method to clean up the service, once it is ended.<\/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.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/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><\/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>The <code>GreetingCard.java<\/code> class is an interface with two methods.<\/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\tpublic void sayHello();\n\t\n\tpublic void sayGoodBye();\n}\n<\/pre>\n<p>The implementation of the service is 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\npublic class GreetingCardImpl implements GreetingCard {\n\n\tpublic void sayHello() {\n\t\tSystem.out.println(\"Hello!!!\");\n\t}\n\n\tpublic void sayGoodBye() {\n\t\tSystem.out.println(\"GoodBye!!!\");\n\t\t\n\t}\n}\n<\/pre>\n<h2>4. Use of the Producer and the Disposer in a Managed Bean<\/h2>\n<p>In the managed bean below, we are making use of the <code>Producer<\/code> and <code>Disposer<\/code> methods created above. In particular, in the  <code>GreetingCardFactory.java<\/code> class, we create a method, <code>getGreetingCard()<\/code>, annotated with the <code>@Produces<\/code> annotation. The method creates an instance of the <code>GreetingCardImpl<\/code>. In the same way, the <code>Disposer<\/code> method has an annotated <code>@Disposes<\/code> parameter. The <code>Disposer<\/code> parameter receives the object produced by the producer method. The <code>Disposer<\/code> method is called automatically when the context ends. Here, since we have created a RequestScoped <code>Producer<\/code> method, the <code>Disposer<\/code> method is called at the end of the request.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>GreetingCardFactory.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.snippets.enterprise.cdibeans;\n\nimport java.io.Serializable;\n\nimport javax.enterprise.context.RequestScoped;\nimport javax.enterprise.inject.Disposes;\nimport javax.enterprise.inject.Produces;\n\nimport com.javacodegeeks.snippets.enterprise.cdibeans.impl.GreetingCardImpl;\n\npublic class GreetingCardFactory implements Serializable {\n\n\tprivate static final long serialVersionUID = -44416514616012281L;\n\n\t@Produces\n\t@RequestScoped\n\t@Greetings\n\tpublic GreetingCard getGreetingCard() {\n\t\tGreetingCard greetingCard = new GreetingCardImpl();\n\t\tgreetingCard.sayHello();\n\t\treturn greetingCard;\n\t}\n\n\tpublic void disposeGreetingCard(\n\t\t\t@Disposes @Greetings GreetingCard greetingCard) {\n\t\tgreetingCard.sayGoodBye();\n\t}\n\n}\n<\/pre>\n<p>We can use qualifiers to provide various implementations of a particular bean type. A qualifier is an annotation that we apply to a bean. A qualifier type is a Java annotation defined as<code> @Target({METHOD, FIELD, PARAMETER, TYPE})<\/code> and <code>@Retention(RUNTIME)<\/code>.<\/p>\n<p>Here, we declare a <code>@Greetings<\/code> qualifier, as shown below:<\/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.ElementType.PARAMETER;\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, PARAMETER })\npublic @interface Greetings {\n\n}\n<\/pre>\n<h2>5. Run the application<\/h2>\n<p>In order to run the application, we have created a simple servlet, 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.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\n\tprivate GreetingCard greetingCard;\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;\" + \"Hello ... \" + \"&lt;\/h1&gt;\");\n\t      System.out.println(\" .... \" + greetingCard.toString());\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\/05\/disp.png\"><img decoding=\"async\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/disp.png\" alt=\"disp\" width=\"891\" height=\"501\" class=\"alignnone size-full wp-image-19124\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/disp.png 891w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/disp-300x168.png 300w\" sizes=\"(max-width: 891px) 100vw, 891px\" \/><\/a><br \/>\n&nbsp;<br \/>\nThis was a tutorial of Java EE CDI Disposer methods.<br \/>\n&nbsp;<br \/>\nDownload the source code of this tutorial: <a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/CDIDisposerMethodExample.zip\">CDIDisposerMethodExample<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a tutorial of CDI Disposer methods. In CDI, since a Producer method generates an object that can then be injected in an application, the Disposer method is used so that the object is removed when its work is completed. A Disposer method is always matched to a Producer method. An example of the &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-12519","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 Disposer methods example<\/title>\n<meta name=\"description\" content=\"This is a tutorial of CDI Disposer methods. In CDI, since a Producer method generates an object that can then be injected in an application, the Disposer\" \/>\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\/05\/java-ee-cdi-disposer-methods-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 Disposer methods example\" \/>\n<meta property=\"og:description\" content=\"This is a tutorial of CDI Disposer methods. In CDI, since a Producer method generates an object that can then be injected in an application, the Disposer\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2013\/05\/java-ee-cdi-disposer-methods-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-05-08T16:19:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-12-09T19:39:40+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\\\/05\\\/java-ee-cdi-disposer-methods-example.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/java-ee-cdi-disposer-methods-example.html\"},\"author\":{\"name\":\"Theodora Fragkouli\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/6bdf5e6534337198ce06de139e9b617b\"},\"headline\":\"Java EE CDI Disposer methods example\",\"datePublished\":\"2013-05-08T16:19:35+00:00\",\"dateModified\":\"2019-12-09T19:39:40+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/java-ee-cdi-disposer-methods-example.html\"},\"wordCount\":765,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/java-ee-cdi-disposer-methods-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\\\/05\\\/java-ee-cdi-disposer-methods-example.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/java-ee-cdi-disposer-methods-example.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/java-ee-cdi-disposer-methods-example.html\",\"name\":\"Java EE CDI Disposer methods example\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/java-ee-cdi-disposer-methods-example.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/java-ee-cdi-disposer-methods-example.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/java-logo.jpg\",\"datePublished\":\"2013-05-08T16:19:35+00:00\",\"dateModified\":\"2019-12-09T19:39:40+00:00\",\"description\":\"This is a tutorial of CDI Disposer methods. In CDI, since a Producer method generates an object that can then be injected in an application, the Disposer\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/java-ee-cdi-disposer-methods-example.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/java-ee-cdi-disposer-methods-example.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/java-ee-cdi-disposer-methods-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\\\/05\\\/java-ee-cdi-disposer-methods-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 Disposer methods 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 Disposer methods example","description":"This is a tutorial of CDI Disposer methods. In CDI, since a Producer method generates an object that can then be injected in an application, the Disposer","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\/05\/java-ee-cdi-disposer-methods-example.html","og_locale":"en_US","og_type":"article","og_title":"Java EE CDI Disposer methods example","og_description":"This is a tutorial of CDI Disposer methods. In CDI, since a Producer method generates an object that can then be injected in an application, the Disposer","og_url":"https:\/\/www.javacodegeeks.com\/2013\/05\/java-ee-cdi-disposer-methods-example.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2013-05-08T16:19:35+00:00","article_modified_time":"2019-12-09T19:39:40+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\/05\/java-ee-cdi-disposer-methods-example.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/05\/java-ee-cdi-disposer-methods-example.html"},"author":{"name":"Theodora Fragkouli","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/6bdf5e6534337198ce06de139e9b617b"},"headline":"Java EE CDI Disposer methods example","datePublished":"2013-05-08T16:19:35+00:00","dateModified":"2019-12-09T19:39:40+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/05\/java-ee-cdi-disposer-methods-example.html"},"wordCount":765,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/05\/java-ee-cdi-disposer-methods-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\/05\/java-ee-cdi-disposer-methods-example.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2013\/05\/java-ee-cdi-disposer-methods-example.html","url":"https:\/\/www.javacodegeeks.com\/2013\/05\/java-ee-cdi-disposer-methods-example.html","name":"Java EE CDI Disposer methods example","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/05\/java-ee-cdi-disposer-methods-example.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/05\/java-ee-cdi-disposer-methods-example.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","datePublished":"2013-05-08T16:19:35+00:00","dateModified":"2019-12-09T19:39:40+00:00","description":"This is a tutorial of CDI Disposer methods. In CDI, since a Producer method generates an object that can then be injected in an application, the Disposer","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/05\/java-ee-cdi-disposer-methods-example.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2013\/05\/java-ee-cdi-disposer-methods-example.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2013\/05\/java-ee-cdi-disposer-methods-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\/05\/java-ee-cdi-disposer-methods-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 Disposer methods 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\/12519","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=12519"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/12519\/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=12519"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=12519"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=12519"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}