-
1. Re: Weld 3 PostConstruct question.
mkouba May 19, 2017 9:50 AM (in response to seto)Hi Seto,
a
@PostConstruct
callback may not define injection points. CDI only supports field, initializer and constructor injection. Also@PostConstruct
callbacks are called after the injection is performed. Weld is probably invoking this method twice - first as a regular initializer - injection is performed. And then a regular callback - idCache is null. -
2. Re: Weld 3 PostConstruct question.
seto May 19, 2017 9:58 AM (in response to mkouba)No. It's called only once.
But now I change it to @Inject for separate field and a post construct method.
When I use Weld 2.x, it told me PostConstruct should be with zero parameters or with parameters with @Inject annotated.
Maybe the warn comes because of the spec is not allowing parameters while weld, as a reference implementation, allows.
-
3. Re: Weld 3 PostConstruct question.
seto May 19, 2017 10:10 AM (in response to seto)Maybe I should a constructor injection to be simpler.
-
4. Re: Weld 3 PostConstruct question.
mkouba May 19, 2017 10:35 AM (in response to seto)Yes, separate the callback and injection (either use initializer or constructor injection). Just out of curiosity - what version of Weld 2 did you use? I've checked the source code of Weld 2.4 and should behave equally.
-
5. Re: Weld 3 PostConstruct question.
seto May 19, 2017 10:37 AM (in response to mkouba)2.4. From 2.4.1 - 2.4.3 is the version I used before. Anyway, I use constructor injection now.
I did print a log, it's only called once in that case.