5 Replies Latest reply on May 19, 2017 10:37 AM by seto

    Weld 3 PostConstruct question.

    seto

      2017-05-19 21:28:08,598 [main] WARN org.jboss.weld.Validator - WELD-001469: Method init defined on class co.kaiba.blueeyes.impl.executor.infinispan.ExecutorImpl is not defined according to the specification. It is annotated with @javax.annotation.PostConstruct but it does not have zero parameters.

      @Inject
      @PostConstruct
      public void init(@Named("DistributedIdCache") AdvancedCache<String, Object> idCache) {
      

      My PostConstruct method is with @Inject and parameters. Why does the warn still come?

        • 1. Re: Weld 3 PostConstruct question.
          mkouba

          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

            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

              Maybe I should a constructor injection to be simpler.

              • 4. Re: Weld 3 PostConstruct question.
                mkouba

                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

                  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.