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