{"id":1591,"date":"2010-10-27T22:02:07","date_gmt":"2010-10-28T03:02:07","guid":{"rendered":"http:\/\/www.andygibson.net\/blog\/?p=1591"},"modified":"2010-10-26T14:03:12","modified_gmt":"2010-10-26T19:03:12","slug":"cdi-alternative-info","status":"publish","type":"post","link":"http:\/\/www.andygibson.net\/blog\/quickbyte\/cdi-alternative-info\/","title":{"rendered":"CDI @Alternative Info"},"content":{"rendered":"<p>The @Alternative CDI annotation allows you to have multiple matching dependencies for a given injection point. This means you can define beans that provide implementations for the same interface without worrying about ambigious dependency errors. When you mark a class with the @Alternative annotation, it is effectively disabled and cannot be considered for injection. The only exception is for the class that is defined in the <code>beans.xml<\/code> configuration file. <\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;alternatives&gt;\r\n\t&lt;class&gt;org.company.project.bean.SomeBean&lt;\/class&gt;\r\n&lt;\/alternatives&gt;\r\n<\/pre>\n<p>Once this bean is identified, it is then used in any injection point that matches for this bean. No other beans for similar injection points can be declared as the &#8216;active&#8217; alternative.<\/p>\n<p>Alternative is really an odd name for it, but all it does is disable the bean while adding it to the <code>beans.xml<\/code> file enables it and makes it available to CDI.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The @Alternative CDI annotation allows you to have multiple matching dependencies for a given injection point. This means you can define beans that provide implementations for the same interface without worrying about ambigious dependency errors. When you mark a class with the @Alternative annotation, it is effectively disabled and cannot be considered for injection. The [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[74],"tags":[49,6,72],"_links":{"self":[{"href":"http:\/\/www.andygibson.net\/blog\/wp-json\/wp\/v2\/posts\/1591"}],"collection":[{"href":"http:\/\/www.andygibson.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.andygibson.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.andygibson.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.andygibson.net\/blog\/wp-json\/wp\/v2\/comments?post=1591"}],"version-history":[{"count":4,"href":"http:\/\/www.andygibson.net\/blog\/wp-json\/wp\/v2\/posts\/1591\/revisions"}],"predecessor-version":[{"id":1595,"href":"http:\/\/www.andygibson.net\/blog\/wp-json\/wp\/v2\/posts\/1591\/revisions\/1595"}],"wp:attachment":[{"href":"http:\/\/www.andygibson.net\/blog\/wp-json\/wp\/v2\/media?parent=1591"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.andygibson.net\/blog\/wp-json\/wp\/v2\/categories?post=1591"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.andygibson.net\/blog\/wp-json\/wp\/v2\/tags?post=1591"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}