<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<base href="https://issues.redhat.com">
<title>Message Title</title>
</head>
<body class="jira" style="color: #333333; font-family: Arial, sans-serif; font-size: 14px; line-height: 1.429">
<table id="background-table" cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; background-color: #f5f5f5; border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt" bgcolor="#f5f5f5">
<!-- header here -->
<tbody>
<tr>
<td id="header-pattern-container" style="padding: 0px; border-collapse: collapse; padding: 10px 20px">
<table id="header-pattern" cellspacing="0" cellpadding="0" border="0" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt">
<tbody>
<tr>
<td id="header-avatar-image-container" valign="top" style="padding: 0px; border-collapse: collapse; vertical-align: top; width: 32px; padding-right: 8px" width="32"> <img id="header-avatar-image" class="image_fix" src="https://static.jboss.org/developer/gravatar/7badf6e89094b134dd4eb65792b7f734?d=mm&s=48" height="32" width="32" border="0" style="border-radius: 3px; vertical-align: top"> </td>
<td id="header-text-container" valign="middle" style="padding: 0px; border-collapse: collapse; vertical-align: middle; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 1px"> <a class="user-hover" rel="vampire" id="email_vampire" href="https://issues.redhat.com/secure/ViewProfile.jspa?name=vampire" style="color:#0066cc;; color: #3b73af; text-decoration: none">Björn Kautler</a> <strong>commented</strong> on <a href="https://issues.redhat.com/browse/WELD-2608" style="color: #3b73af; text-decoration: none"><img src="cid:jira-generated-image-avatar-58599fde-3291-434e-b8ea-0cd8e84dc81d" height="16" width="16" border="0" align="absmiddle" alt="Bug"> WELD-2608</a> </td>
</tr>
</tbody>
</table> </td>
</tr>
<tr>
<td id="email-content-container" style="padding: 0px; border-collapse: collapse; padding: 0 20px">
<table id="email-content-table" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; border-spacing: 0; border-collapse: separate">
<tbody>
<tr>
<!-- there needs to be content in the cell for it to render in some clients -->
<td class="email-content-rounded-top mobile-expand" style="padding: 0px; border-collapse: collapse; color: #ffffff; padding: 0 15px 0 16px; height: 15px; background-color: #ffffff; border-left: 1px solid #cccccc; border-top: 1px solid #cccccc; border-right: 1px solid #cccccc; border-bottom: 0; border-top-right-radius: 5px; border-top-left-radius: 5px; height: 10px; line-height: 10px; padding: 0 15px 0 16px; mso-line-height-rule: exactly" height="10" bgcolor="#ffffff"> </td>
</tr>
<tr>
<td class="email-content-main mobile-expand " style="padding: 0px; border-collapse: collapse; border-left: 1px solid #cccccc; border-right: 1px solid #cccccc; border-top: 0; border-bottom: 0; padding: 0 15px 0 16px; background-color: #ffffff" bgcolor="#ffffff">
<table class="page-title-pattern" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt">
<tbody>
<tr>
<td style="vertical-align: top;; padding: 0px; border-collapse: collapse; padding-right: 5px; font-size: 20px; line-height: 30px; mso-line-height-rule: exactly" class="page-title-pattern-header-container"> <span class="page-title-pattern-header" style="font-family: Arial, sans-serif; padding: 0; font-size: 20px; line-height: 30px; mso-text-raise: 2px; mso-line-height-rule: exactly; vertical-align: middle"> <a href="https://issues.redhat.com/browse/WELD-2608" style="color: #3b73af; text-decoration: none">Re: Adding a bean using AfterBeanDiscovery does not register its observer methods</a> </span> </td>
</tr>
</tbody>
</table> </td>
</tr>
<tr>
<td id="text-paragraph-pattern-top" class="email-content-main mobile-expand comment-top-pattern" style="padding: 0px; border-collapse: collapse; border-left: 1px solid #cccccc; border-right: 1px solid #cccccc; border-top: 0; border-bottom: 0; padding: 0 15px 0 16px; background-color: #ffffff; border-bottom: none; padding-bottom: 0" bgcolor="#ffffff">
<table class="text-paragraph-pattern" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 2px">
<tbody>
<tr>
<td class="text-paragraph-pattern-container mobile-resize-text " style="padding: 0px; border-collapse: collapse; padding: 0 0 10px 0">
<blockquote style="margin: 10px 0 0 0; margin-top: 0; border-left: 1px solid #cccccc; color: #707070; margin-left: 19px; padding: 10px 20px">
<p style="margin: 10px 0 0 0; margin-top: 0">So you are only annotating the class with @Alternative in order for them not to be automatically picked up and used as beans?</p>
</blockquote> <p style="margin: 10px 0 0 0">Exactly</p>
<blockquote style="margin: 10px 0 0 0; border-left: 1px solid #cccccc; color: #707070; margin-left: 19px; padding: 10px 20px">
<p style="margin: 10px 0 0 0; margin-top: 0">If you don't have discovery mode all, then you shouldn't need this at all.</p>
</blockquote> <p style="margin: 10px 0 0 0">They are also annotated <tt>@ApplicationScoped</tt>, so they would be picked up enabled without <tt>@Alternative</tt>, this way they are picked up, but not enabled and I just add them a second time but this time as non-alternative.</p>
<blockquote style="margin: 10px 0 0 0; border-left: 1px solid #cccccc; color: #707070; margin-left: 19px; padding: 10px 20px">
<p style="margin: 10px 0 0 0; margin-top: 0">If you do have it, then Weld will discover these anyway, it will just not enable them (and you might as well just listen for these beans in ProcessAnnotatedType observer and conditionally remove the annotation there which will result in the bean being picked up and used without any manual registration).</p>
</blockquote> <p style="margin: 10px 0 0 0">Ah, perfect, this is what I actually was after then <img class="emoticon" src="cid:jira-generated-image-static-smile-67e50df5-b19a-4767-a462-b208868a4c7b" height="16" width="16" align="absmiddle" alt="" border="0"></p>
<blockquote style="margin: 10px 0 0 0; border-left: 1px solid #cccccc; color: #707070; margin-left: 19px; padding: 10px 20px">
<p style="margin: 10px 0 0 0; margin-top: 0">Furthermore, if you mean to have them as classes that are normally left alone by discovery, then you can use @Vetoed instead.</p>
</blockquote> <p style="margin: 10px 0 0 0">Ah, even better, this way I save the "effort" of having all the alternate beans that will not get enabled, so I mark the beans as <tt>@Vetoed</tt> and then use <tt>BeforeBeanDiscovery#addAnnotatedType(...)</tt> removing the <tt>@Vetoed</tt> instead of the <tt>@Alternative</tt> annotation.</p> <p style="margin: 10px 0 0 0">Is it expected that unlike <tt>@Alternate</tt> you cannot apply <tt>@Vetoed</tt> using a stereotype?</p>
<blockquote style="margin: 10px 0 0 0; border-left: 1px solid #cccccc; color: #707070; margin-left: 19px; padding: 10px 20px">
<p style="margin: 10px 0 0 0; margin-top: 0">And last thing I can think of is that you can also specify filters in beans.xml that exclude certain packages from discovery - that way you could leave out the alternative annotation and not have the beans picked up a</p>
</blockquote> <p style="margin: 10px 0 0 0">Hm, that sounds very interesting, but will not work with standard setup, as this is for integ tests run from Gradle, where the classes and resources are in separate folders on the class path, so the <tt>beans.xml</tt> would not be picked up as the two directories are considered individual bean archives and I do not see a way to define exclude patterns via <tt>SeContainerInitializer</tt>.</p> <p style="margin: 10px 0 0 0">Or is there a way to configure the excludes via <tt>SeContainerInitializer</tt>?<br> Because that is exactly what I would like to have I think, not having any beans in the integ test sources being added explicitly and then using <tt>SeContainerInitializer#addBeanClasses</tt> to add the bean classes I want for the current test.</p> <p style="margin: 10px 0 0 0">But anyway, this was very valuable information, because I actually need <tt><exclude ...><if-class-not-available .../></exclude></tt> in my production code.<br> Up to now the respective beans just failed to be generated with WELD-000119, but as this was on <tt>INFO</tt> level, I just accepted it, but having class-dependent excludes is much better of course.</p>
<blockquote style="margin: 10px 0 0 0; border-left: 1px solid #cccccc; color: #707070; margin-left: 19px; padding: 10px 20px">
<p style="margin: 10px 0 0 0; margin-top: 0">Why am I explaining that? To illustrate what happens with your current solution (assuming discovery mode "all") - Weld will discover the class annotated with @Alternative on its own a register it, the bean isn't enabled, so it isn't used. The you come in and register another annotated type manually (for the same class) and that one comes without @Alternative and will be used.<br> So you are basically duplicating that class as a bean (but there will be no clash in this case).</p>
</blockquote> <p style="margin: 10px 0 0 0">Yeah, I was aware that this is what I'm doing, I just didn't know about the other ways. <img class="emoticon" src="cid:jira-generated-image-static-smile-67e50df5-b19a-4767-a462-b208868a4c7b" height="16" width="16" align="absmiddle" alt="" border="0"><br> So your explanations and expert insight is most appreciated, thanks again.</p>
<blockquote style="margin: 10px 0 0 0; border-left: 1px solid #cccccc; color: #707070; margin-left: 19px; padding: 10px 20px">
<p style="margin: 10px 0 0 0; margin-top: 0">> .addAnnotatedType(it, null)</p>
<p style="margin: 10px 0 0 0">Don't use null in place of ID, pick some; even if it's equal to bean's class name plus some suffix. The reason for ID is that there is a situation where you can have multiple annotated types for one underlying class (if I recall correctly).</p>
</blockquote> <p style="margin: 10px 0 0 0">I see, I just copied the variant with <tt>null</tt> from <tt>BeforeBeanDiscoveryImpl#addAnnotatedType(javax.enterprise.inject.spi.AnnotatedType<?>)</tt> where it uses <tt>null</tt> as second parameter.<br> Why "plus some suffix"?<br> Is any random value fine, like for example then <tt>beforeBeanDiscovery.addAnnotatedType(clazz, clazz.getName() + " " + UUID.randomUUID())</tt></p>
<blockquote style="margin: 10px 0 0 0; border-left: 1px solid #cccccc; color: #707070; margin-left: 19px; padding: 10px 20px">
<p style="margin: 10px 0 0 0; margin-top: 0">> as addAnnotatedType(AnnotatedType<?>, String) does not return an AnnotatedTypeConfigurator where I could remove the @Alternative annotation.</p>
<p style="margin: 10px 0 0 0">Using configurator is just as fine, but like I said above, you might want to look into other ways to conditionally add a bean.</p>
</blockquote> <p style="margin: 10px 0 0 0">That was more a sad gibe, that <tt>addAnnotatedType(AnnotatedType<?>, String)</tt> should better also return an <tt>AnnotatedTypeConfigurator</tt>, but I guess this is not possible due to binary compatibility with code compiled against earlier versions. :-D</p>
<blockquote style="margin: 10px 0 0 0; border-left: 1px solid #cccccc; color: #707070; margin-left: 19px; padding: 10px 20px">
<p style="margin: 10px 0 0 0; margin-top: 0">Hope this isn't too confusing</p>
</blockquote> <p style="margin: 10px 0 0 0">Not at all, but rather educating <img class="emoticon" src="cid:jira-generated-image-static-smile-67e50df5-b19a-4767-a462-b208868a4c7b" height="16" width="16" align="absmiddle" alt="" border="0"></p> </td>
</tr>
</tbody>
</table> </td>
</tr>
<tr>
<td class="email-content-main mobile-expand " style="padding: 0px; border-collapse: collapse; border-left: 1px solid #cccccc; border-right: 1px solid #cccccc; border-top: 0; border-bottom: 0; padding: 0 15px 0 16px; background-color: #ffffff" bgcolor="#ffffff">
<table id="actions-pattern" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 1px">
<tbody>
<tr>
<td id="actions-pattern-container" valign="middle" style="padding: 0px; border-collapse: collapse; padding: 10px 0 10px 24px; vertical-align: middle; padding-left: 0">
<table align="left" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt">
<tbody>
<tr>
<td class="actions-pattern-action-icon-container" style="padding: 0px; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 0; vertical-align: middle"> <a href="https://issues.redhat.com/browse/WELD-2608#add-comment" target="_blank" title="Add Comment" style="color: #3b73af; text-decoration: none"> <img class="actions-pattern-action-icon-image" src="cid:jira-generated-image-static-comment-icon-2620485c-a861-41f0-8914-994a0fd0fc89" alt="Add Comment" title="Add Comment" height="16" width="16" border="0" style="vertical-align: middle"> </a> </td>
<td class="actions-pattern-action-text-container" style="padding: 0px; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 4px; padding-left: 5px"> <a href="https://issues.redhat.com/browse/WELD-2608#add-comment" target="_blank" title="Add Comment" style="color: #3b73af; text-decoration: none">Add Comment</a> </td>
</tr>
</tbody>
</table> </td>
</tr>
</tbody>
</table> </td>
</tr>
<!-- there needs to be content in the cell for it to render in some clients -->
<tr>
<td class="email-content-rounded-bottom mobile-expand" style="padding: 0px; border-collapse: collapse; color: #ffffff; padding: 0 15px 0 16px; height: 5px; line-height: 5px; background-color: #ffffff; border-top: 0; border-left: 1px solid #cccccc; border-bottom: 1px solid #cccccc; border-right: 1px solid #cccccc; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; mso-line-height-rule: exactly" height="5" bgcolor="#ffffff"> </td>
</tr>
</tbody>
</table> </td>
</tr>
<tr>
<td id="footer-pattern" style="padding: 0px; border-collapse: collapse; padding: 12px 20px">
<table id="footer-pattern-container" cellspacing="0" cellpadding="0" border="0" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt">
<tbody>
<tr>
<td id="footer-pattern-text" class="mobile-resize-text" width="100%" style="padding: 0px; border-collapse: collapse; color: #999999; font-size: 12px; line-height: 18px; font-family: Arial, sans-serif; mso-line-height-rule: exactly; mso-text-raise: 2px"> This message was sent by Atlassian Jira <span id="footer-build-information">(v7.13.8#713008-<span title="1606a5c1e7006e1ab135aac81f7a9566b2dbc3a6" data-commit-id="1606a5c1e7006e1ab135aac81f7a9566b2dbc3a6}">sha1:1606a5c</span>)</span> </td>
<td id="footer-pattern-logo-desktop-container" valign="top" style="padding: 0px; border-collapse: collapse; padding-left: 20px; vertical-align: top">
<table style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt">
<tbody>
<tr>
<td id="footer-pattern-logo-desktop-padding" style="padding: 0px; border-collapse: collapse; padding-top: 3px"> <img id="footer-pattern-logo-desktop" src="https://issues.redhat.com/images/mail/atlassian-email-logo.png" alt="Atlassian logo" title="Atlassian logo" width="191" height="24" class="image_fix"> </td>
</tr>
</tbody>
</table> </td>
</tr>
</tbody>
</table> </td>
</tr>
</tbody>
</table>
</body>
</html>