<HTML><BODY>Hi Martin<br><br>Thank you for your answer. <br><br>1) I don't inject Test class anywhere.<br>2) I modified init and destroy methods:<br>&nbsp;&nbsp;&nbsp; public void init(@Observes @Initialized(ApplicationScoped.class) Object init) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(init);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println("Test was initialized");<br>&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp; public void destroy(@Observes @Destroyed(ApplicationScoped.class) Object init) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(init);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println("Test was destroyed.");<br>&nbsp;&nbsp;&nbsp; }<br><br>Now on bundle start:<br><br>Test was created.<br>Application context initialized.<br>Test was initialized<br>java.lang.Object@48813e62<br>Test was initialized<br><br>Now on bundle stop:<br><br>java.lang.Object@48813e62<br>Test was destroyed.<br>Test was created.<br>Application context destroyed.<br>Test was destroyed.<br><br><br><blockquote style="border-left:1px solid #0857A6; margin:10px; padding:0 0 0 10px;">
        Понедельник, 22 мая 2017, 10:48 +03:00 от Martin Kouba &lt;mkouba@redhat.com&gt;:<br>
        <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_14954393280000000495_BODY">Hi Alex,<br>
<br>
this looks really weird. Could you try to print out the event payload, <br>
e.g. System.out.println(init)?<br>
<br>
Also you should be always very careful when using code inside the <br>
no-args constructor of a normal-scoped bean -&gt; it will be also executed <br>
when creating a client proxy. In your case, if you do @Inject Test and <br>
invoke any method then you will also see "Test was created" printed twice.<br>
<br>
Martin<br>
<br>
Dne 22.5.2017 v 08:50 Alex Sviridov napsal(a):<br>
&gt; Hi all<br>
&gt; <br>
&gt; I use pax-cdi -1.0.0.RC2 and weld 2.3.5.Final and this is my test class:<br>
&gt; <br>
&gt; import javax.enterprise.context.ApplicationScoped;<br>
&gt; import javax.enterprise.context.Destroyed;<br>
&gt; import javax.enterprise.context.Initialized;<br>
&gt; import javax.enterprise.event.Observes;<br>
&gt; <br>
&gt; @ApplicationScoped<br>
&gt; public class Test {<br>
&gt; <br>
&gt;      public Test() {<br>
&gt;          System.out.println("Test was created.");<br>
&gt;      }<br>
&gt; <br>
&gt;      public void init(@Observes @Initialized(ApplicationScoped.class) Object<br>
&gt; init) {<br>
&gt;          System.out.println("Test was initialized");<br>
&gt;      }<br>
&gt; <br>
&gt;      public void destroy(@Observes @Destroyed(ApplicationScoped.class)<br>
&gt; Object init) {<br>
&gt;          System.out.println("Test was destroyed.");<br>
&gt;      }<br>
&gt; }<br>
&gt; <br>
&gt; When I start test-bundle I see the following output:<br>
&gt; Test was created.<br>
&gt; Test was initialized<br>
&gt; Test was initialized<br>
&gt; When I stop test-bundle I see the following output:<br>
&gt; Test was destroyed.<br>
&gt; Test was created.<br>
&gt; Test was destroyed.<br>
&gt; <br>
&gt; So as result this bean was two times created, two times initialized and two<br>
&gt; times destroyed.<br>
&gt; <br>
&gt; I expected that this bean must be once created, one initialized and once<br>
&gt; destroyed.<br>
&gt; <br>
&gt; Is this a bug that must be reported or my mistake?<br>
&gt; <br>
&gt; -- <br>
&gt; Alex Sviridov<br>
&gt; <br>
&gt; <br>
&gt; _______________________________________________<br>
&gt; weld-dev mailing list<br>
&gt; <a href="mailto:weld-dev@lists.jboss.org">weld-dev@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/weld-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/weld-dev</a><br>
&gt; <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>