<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> public void init(@Observes @Initialized(ApplicationScoped.class) Object init) {<br> System.out.println(init);<br> System.out.println("Test was initialized");<br> }<br><br> public void destroy(@Observes @Destroyed(ApplicationScoped.class) Object init) {<br> System.out.println(init);<br> System.out.println("Test was destroyed.");<br> }<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 <mkouba@redhat.com>:<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 -> 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>
> Hi all<br>
> <br>
> I use pax-cdi -1.0.0.RC2 and weld 2.3.5.Final and this is my test class:<br>
> <br>
> import javax.enterprise.context.ApplicationScoped;<br>
> import javax.enterprise.context.Destroyed;<br>
> import javax.enterprise.context.Initialized;<br>
> import javax.enterprise.event.Observes;<br>
> <br>
> @ApplicationScoped<br>
> public class Test {<br>
> <br>
> public Test() {<br>
> System.out.println("Test was created.");<br>
> }<br>
> <br>
> public void init(@Observes @Initialized(ApplicationScoped.class) Object<br>
> init) {<br>
> System.out.println("Test was initialized");<br>
> }<br>
> <br>
> public void destroy(@Observes @Destroyed(ApplicationScoped.class)<br>
> Object init) {<br>
> System.out.println("Test was destroyed.");<br>
> }<br>
> }<br>
> <br>
> When I start test-bundle I see the following output:<br>
> Test was created.<br>
> Test was initialized<br>
> Test was initialized<br>
> When I stop test-bundle I see the following output:<br>
> Test was destroyed.<br>
> Test was created.<br>
> Test was destroyed.<br>
> <br>
> So as result this bean was two times created, two times initialized and two<br>
> times destroyed.<br>
> <br>
> I expected that this bean must be once created, one initialized and once<br>
> destroyed.<br>
> <br>
> Is this a bug that must be reported or my mistake?<br>
> <br>
> -- <br>
> Alex Sviridov<br>
> <br>
> <br>
> _______________________________________________<br>
> weld-dev mailing list<br>
> <a href="mailto:weld-dev@lists.jboss.org">weld-dev@lists.jboss.org</a><br>
> <a href="https://lists.jboss.org/mailman/listinfo/weld-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/weld-dev</a><br>
> <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>