<HTML><BODY>Martin,<br><br>Thank you for your answer. I replaced 2.3.5.Final with 2.2.16.Final. Besides in 2.2.16 in<br>manifest I had to export package org.jboss.weld.config which is used by pax-cdi. <br><br>Now&nbsp; on bundle start:<br>Test was created.<br>java.lang.Object@6bc3928f<br>Test was initialized<br><br>Now&nbsp; on bundle stop:<br>java.lang.Object@6bc3928f<br>Test was destroyed.<br><br>Понедельник, 22 мая 2017, 12:27 +03:00 от Martin Kouba &lt;mkouba@redhat.com&gt;:<br><blockquote style="border-left:1px solid #0857A6; margin:10px; padding:0 0 0 10px;">
        <br>
        <div id="">






















        












<div class="js-helper js-readmsg-msg">
        <style type="text/css"></style>
         <div>
                <base target="_self" href="https://e.mail.ru/">
                
            <div id="style_14954452670000000208_BODY">Dne 22.5.2017 v 11:14 Alex Sviridov napsal(a):<br>
&gt; Martin,<br>
&gt; <br>
&gt; In your message you wrote : "Up to version 2.2 Weld did not fire <br>
&gt; @Initialized/@Destroyed events for<br>
&gt; @ApplicationScoped for non-web modules.".<br>
&gt; <br>
&gt; In WELD-2389 you wrote : "Right now, this service is registered for any <br>
&gt; non-SE environment".<br>
&gt; <br>
&gt; I use OSGi + PAX-CDI + WELD + JAVAFX. As I suppose this is a SE <br>
&gt; application (not EE).<br>
&gt; Could you explain "Right now, this service is registered for any non-SE <br>
&gt; environment" ?<br>
<br>
Well, I'm talking about Weld SPI and I'm refering to the environment <br>
info provided by the integrator. PAX CDI provides a custom <br>
implementation of org.jboss.weld.bootstrap.api.Environment, which is <br>
fine. The problem is that Weld currently skips registration only if <br>
org.jboss.weld.bootstrap.api.Environments.SE is used.<br>
<br>
&gt; <br>
&gt; Best regards, Alex<br>
&gt; <br>
&gt; <br>
&gt;     Понедельник, 22 мая 2017, 11:51 +03:00 от Martin Kouba<br>
&gt;     &lt;<a href="mailto:mkouba@redhat.com">mkouba@redhat.com</a>&gt;:<br>
&gt; <br>
&gt;     Ok, now I know what's going on.<br>
&gt; <br>
&gt;     The event with payload "Application context initialized." comes<br>
&gt;     directly<br>
&gt;     from Weld. Whereas the second one java.lang.Object@48813e62 comes from<br>
&gt;     PAX CDI [1].<br>
&gt; <br>
&gt;     Up to version 2.2 Weld did not fire @Initialized/@Destroyed events for<br>
&gt;     @ApplicationScoped for non-web modules. The behavior changed in 2.3 -<br>
&gt;     see also WELD-1821 [2].<br>
&gt; <br>
&gt;     This explains the events fired twice.<br>
&gt; <br>
&gt;     WRT Test bean instance created twice - the problem is that<br>
&gt;     @Destroyed(ApplicationScoped.class) event is fired after the actual<br>
&gt;     destruction. So if you declare an observer on an @ApplicationScoped<br>
&gt;     you're entering the "undefined behavior zone". In Weld, the Test<br>
&gt;     bean is<br>
&gt;     created again.<br>
&gt; <br>
&gt;     I've created WELD-2389 [3] to track this issue.<br>
&gt; <br>
&gt;     Thanks,<br>
&gt; <br>
&gt;     Martin<br>
&gt; <br>
&gt;     [1]<br>
&gt;     <a href="https://github.com/ops4j/org.ops4j.pax.cdi/blob/master/pax-cdi-weld/src/main/java/org/ops4j/pax/cdi/weld/impl/WeldCdiContainer.java#L154" target="_blank">https://github.com/ops4j/org.ops4j.pax.cdi/blob/master/pax-cdi-weld/src/main/java/org/ops4j/pax/cdi/weld/impl/WeldCdiContainer.java#L154</a><br>
&gt; <br>
&gt;     [2]<br>
&gt;     <a href="https://issues.jboss.org/browse/WELD-1821" target="_blank">https://issues.jboss.org/browse/WELD-1821</a><br>
&gt; <br>
&gt;     [3]<br>
&gt;     <a href="https://issues.jboss.org/browse/WELD-2389" target="_blank">https://issues.jboss.org/browse/WELD-2389</a><br>
&gt; <br>
&gt; <br>
&gt;     Dne 22.5.2017 v 09:57 Alex Sviridov napsal(a):<br>
&gt;      &gt; Hi Martin<br>
&gt;      &gt;<br>
&gt;      &gt; Thank you for your answer.<br>
&gt;      &gt;<br>
&gt;      &gt; 1) I don't inject Test class anywhere.<br>
&gt;      &gt; 2) I modified init and destroy methods:<br>
&gt;      &gt; public void init(@Observes @Initialized(ApplicationScoped.class)<br>
&gt;      &gt; Object init) {<br>
&gt;      &gt; System.out.println(init);<br>
&gt;      &gt; System.out.println("Test was initialized");<br>
&gt;      &gt; }<br>
&gt;      &gt;<br>
&gt;      &gt; public void destroy(@Observes @Destroyed(ApplicationScoped.class)<br>
&gt;      &gt; Object init) {<br>
&gt;      &gt; System.out.println(init);<br>
&gt;      &gt; System.out.println("Test was destroyed.");<br>
&gt;      &gt; }<br>
&gt;      &gt;<br>
&gt;      &gt; Now on bundle start:<br>
&gt;      &gt;<br>
&gt;      &gt; Test was created.<br>
&gt;      &gt; Application context initialized.<br>
&gt;      &gt; Test was initialized<br>
&gt;      &gt; java.lang.Object@48813e62<br>
&gt;      &gt; Test was initialized<br>
&gt;      &gt;<br>
&gt;      &gt; Now on bundle stop:<br>
&gt;      &gt;<br>
&gt;      &gt; java.lang.Object@48813e62<br>
&gt;      &gt; Test was destroyed.<br>
&gt;      &gt; Test was created.<br>
&gt;      &gt; Application context destroyed.<br>
&gt;      &gt; Test was destroyed.<br>
&gt;      &gt;<br>
&gt;      &gt;<br>
&gt;      &gt; Понедельник, 22 мая 2017, 10:48 +03:00 от Martin Kouba<br>
&gt;      &gt; &lt;<a href="mailto:mkouba@redhat.com">mkouba@redhat.com</a> &lt;mailto:<a href="mailto:mkouba@redhat.com">mkouba@redhat.com</a>&gt;&gt;:<br>
&gt;      &gt;<br>
&gt;      &gt; Hi Alex,<br>
&gt;      &gt;<br>
&gt;      &gt; this looks really weird. Could you try to print out the event<br>
&gt;     payload,<br>
&gt;      &gt; e.g. System.out.println(init)?<br>
&gt;      &gt;<br>
&gt;      &gt; Also you should be always very careful when using code inside the<br>
&gt;      &gt; no-args constructor of a normal-scoped bean -&gt; it will be also<br>
&gt;     executed<br>
&gt;      &gt; when creating a client proxy. In your case, if you do @Inject<br>
&gt;     Test and<br>
&gt;      &gt; invoke any method then you will also see "Test was created" printed<br>
&gt;      &gt; twice.<br>
&gt;      &gt;<br>
&gt;      &gt; Martin<br>
&gt;      &gt;<br>
&gt;      &gt; Dne 22.5.2017 v 08:50 Alex Sviridov napsal(a):<br>
&gt;      &gt; &gt; Hi all<br>
&gt;      &gt; &gt;<br>
&gt;      &gt; &gt; I use pax-cdi -1.0.0.RC2 and weld 2.3.5.Final and this is my test<br>
&gt;      &gt; class:<br>
&gt;      &gt; &gt;<br>
&gt;      &gt; &gt; import javax.enterprise.context.ApplicationScoped;<br>
&gt;      &gt; &gt; import javax.enterprise.context.Destroyed;<br>
&gt;      &gt; &gt; import javax.enterprise.context.Initialized;<br>
&gt;      &gt; &gt; import javax.enterprise.event.Observes;<br>
&gt;      &gt; &gt;<br>
&gt;      &gt; &gt; @ApplicationScoped<br>
&gt;      &gt; &gt; public class Test {<br>
&gt;      &gt; &gt;<br>
&gt;      &gt; &gt; public Test() {<br>
&gt;      &gt; &gt; System.out.println("Test was created.");<br>
&gt;      &gt; &gt; }<br>
&gt;      &gt; &gt;<br>
&gt;      &gt; &gt; public void init(@Observes @Initialized(ApplicationScoped.class)<br>
&gt;      &gt; Object<br>
&gt;      &gt; &gt; init) {<br>
&gt;      &gt; &gt; System.out.println("Test was initialized");<br>
&gt;      &gt; &gt; }<br>
&gt;      &gt; &gt;<br>
&gt;      &gt; &gt; public void destroy(@Observes @Destroyed(ApplicationScoped.class)<br>
&gt;      &gt; &gt; Object init) {<br>
&gt;      &gt; &gt; System.out.println("Test was destroyed.");<br>
&gt;      &gt; &gt; }<br>
&gt;      &gt; &gt; }<br>
&gt;      &gt; &gt;<br>
&gt;      &gt; &gt; When I start test-bundle I see the following output:<br>
&gt;      &gt; &gt; Test was created.<br>
&gt;      &gt; &gt; Test was initialized<br>
&gt;      &gt; &gt; Test was initialized<br>
&gt;      &gt; &gt; When I stop test-bundle I see the following output:<br>
&gt;      &gt; &gt; Test was destroyed.<br>
&gt;      &gt; &gt; Test was created.<br>
&gt;      &gt; &gt; Test was destroyed.<br>
&gt;      &gt; &gt;<br>
&gt;      &gt; &gt; So as result this bean was two times created, two times<br>
&gt;      &gt; initialized and two<br>
&gt;      &gt; &gt; times destroyed.<br>
&gt;      &gt; &gt;<br>
&gt;      &gt; &gt; I expected that this bean must be once created, one initialized<br>
&gt;      &gt; and once<br>
&gt;      &gt; &gt; destroyed.<br>
&gt;      &gt; &gt;<br>
&gt;      &gt; &gt; Is this a bug that must be reported or my mistake?<br>
&gt;      &gt; &gt;<br>
&gt;      &gt; &gt; --<br>
&gt;      &gt; &gt; Alex Sviridov<br>
&gt;      &gt; &gt;<br>
&gt;      &gt; &gt;<br>
&gt;      &gt; &gt; _______________________________________________<br>
&gt;      &gt; &gt; weld-dev mailing list<br>
&gt;      &gt; &gt; <a href="mailto:weld-dev@lists.jboss.org">weld-dev@lists.jboss.org</a> &lt;mailto:<a href="mailto:weld-dev@lists.jboss.org">weld-dev@lists.jboss.org</a>&gt;<br>
&gt;     &lt;mailto:<a href="mailto:weld-dev@lists.jboss.org">weld-dev@lists.jboss.org</a> &lt;mailto:<a href="mailto:weld-dev@lists.jboss.org">weld-dev@lists.jboss.org</a>&gt;&gt;<br>
&gt;      &gt; &gt; <a href="https://lists.jboss.org/mailman/listinfo/weld-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/weld-dev</a><br>
&gt;      &gt; &gt;<br>
&gt;      &gt;<br>
&gt;      &gt; --<br>
&gt;      &gt; Martin Kouba<br>
&gt;      &gt; Senior Software Engineer<br>
&gt;      &gt; Red Hat, Czech Republic<br>
&gt;      &gt;<br>
&gt;      &gt;<br>
&gt;      &gt;<br>
&gt;      &gt; --<br>
&gt;      &gt; Alex Sviridov<br>
&gt; <br>
&gt;     -- <br>
&gt;     Martin Kouba<br>
&gt;     Senior Software Engineer<br>
&gt;     Red Hat, Czech Republic<br>
&gt; <br>
&gt; <br>
&gt; <br>
&gt; -- <br>
&gt; Alex Sviridov<br>
<br>
-- <br>
Martin Kouba<br>
Senior Software Engineer<br>
Red Hat, Czech Republic<br>
</div>
            
        
                <base target="_self" href="https://e.mail.ru/">
        </div>

        
</div>


</div>
</blockquote>
<br>
<br>-- <br>Alex Sviridov<br></BODY></HTML>