Weld developers suggested another way with using weld 2.3.5:

@ApplicationScoped
class Test {

    public Test() {
        System.out.println("Test was created.");
    }

    void appContextInit(@Observes @Initialized(ApplicationScoped.class) 
Object init) {
      // Empty body - force eager instantiation
    }

    @PostConstruct
    void onInit() {
      // logic... will only be called once
      System.out.println("Test was initialized");
    }

    @PreDestroy
    void onDestroy() {
      // logic.... will be called once before
        System.out.println("Test was destroyed.");
    }

}

They say that Weld 2.4.4.Final (that should fix this bug) will 
approximately released Jun/17.

понедельник, 22 мая 2017 г., 13:37:33 UTC+3 пользователь Marc Schlegel 
написал:
>
> Hi Pavel. Thanks for your findings regarding the Weld issues and providing 
> a workaround.
>
> BTW: I doubt that you will get more answers by posting jokes about the 
> community. Please keep in mind that PAX-CDI 1.0.0 is not released yet, so 
> there are probably not many people using it yet. 
>
> regards
> Marc
>
> Am Montag, 22. Mai 2017 12:15:34 UTC+2 schrieb Pavel:
>>
>> Hi all
>>
>> With developers of WELD the problem was found out. 
>>
>> Up to version 2.2 Weld did not fire @Initialized/@Destroyed events for
>>   @ApplicationScoped for non-web modules. The behavior changed in 2.3 -
>>  see also WELD-1821 [2]. Issue WELD-2389 [3] was created.
>>
>> So, @ApplicationScoped events are broken in PAX-CDI 1.0.0.RC2 
>> that uses weld 2.3.5.Final and such beans are not singletons.
>>
>> As a workaround I replaced 2.3.5.Final with 2.2.16.Final. Besides in 
>> 2.2.16 in
>> manifest I had to export package org.jboss.weld.config which is used by 
>> pax-cdi.  
>>
>> Now  on bundle start:
>> Test was created.
>> Test was initialized
>>
>> Now  on bundle stop:
>> Test was destroyed.
>>
>> JOKE: What is common in working with PAX-CDI and searching for 
>> extraterrestrial civilizations?
>> You send messages and hope to get answer. But... no, not any message 
>> ever...
>>
>> [2] https://issues.jboss.org/browse/WELD-1821
>>
>> [3] https://issues.jboss.org/browse/WELD-2389
>>
>>
>> воскресенье, 21 мая 2017 г., 21:51:26 UTC+3 пользователь Pavel написал:
>>>
>>> Hi all
>>>
>>> Sorry for one more message but I have rather strange situation.  I use 
>>> pax-cdi -1.0.0.RC2 and weld 2.3.5.Final.
>>>
>>> This is the 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?
>>>
>>> Best regards, Pavel
>>>
>>>
>>>

-- 
-- 
------------------
OPS4J - http://www.ops4j.org - [email protected]

--- 
You received this message because you are subscribed to the Google Groups 
"OPS4J" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to