What are the best debugging tricks with Weld/CDI?

前端 未结 3 1813
梦谈多话
梦谈多话 2021-01-31 09:21

One of the beauties with Java EE 6 is the new dependency injection framework - CDI with the Weld reference implementation - which has prompted us to start migrating internally t

3条回答
  •  广开言路
    2021-01-31 10:14

    I can suggest a few options:

    • lower the logging threshold. I don't know what logging framework is used by Weld, but you can see that and configure, say, DEBUG or INFO

    • get the source code and put breakpoints in the BeanManager implementation (BeanManagerImpl perhaps). It is the main class in CDI and handles almost everything.

    • Try putting a different implementation (if not tied by the application server) - for example OpenWebBeans. Its exception messages might be better

    • Open the specification and read about the particular case. It is often the case the you have missed a given precondition - for example an annotation has to have a specific @Target, otherwise it is not handled by CDI.

    I can confirm that the exception messages of Weld are rather disappointing. I haven't used Guice, but in Spring they are very, very informative. With Weld I had to refer to the 4th point above (opened the spec) and verify all preconditions. This was my suspicion initially - that even though the spec looks very good, the implementations will not be as shiny (at first at least). But I guess one gets used to this.

提交回复
热议问题