Weld / CDI最好的调试技巧是什么? [英] What are the best debugging tricks with Weld/CDI?

查看:196
本文介绍了Weld / CDI最好的调试技巧是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java EE 6的优点之一是新的依赖注入框架 - 带有Weld参考实现的CDI - 它促使我们以一种与实现无关的方式开始内部迁移到JSR-330,其明确目标是能够实现有一个冷冻的核心罐,然后能够添加额外的罐子,提供新的模块替换核心罐中的功能。

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 to JSR-330 in an implementation agnostic manner, with the explicit target of being able to have a core jar which is frozen, and then being able to add extra jars providing new modules replacing functionality in the core jar.

我现在正在制作以上与韦尔德的合作,坦白说,封面背后有太多的魔力。无论是有效还是无效,默认情况下它不会提供很多帮助,因此您可以调查错误并修复它。

I am now in the process of making the above work with Weld, and to be frank there is simply too much magic going on behind the covers. Either it works or it doesn't, and it doesn't provide very much help by default on what happens so you can investigate what is wrong and fix it.

I我希望有开关可以轻松启用以下内容:

I would expect that there are switches to switch which can easily enable things like:


  • 扫描哪些类路径条目以及在哪里?结果是什么?

  • 哪些bean可以注入哪个类?

  • 是什么导致给定的bean以后不被考虑?给定的jar?

换句话说,我需要更详细地看到决策过程。出于某种原因,Guice不需要这样做,也许是因为魔法少得多,也许是因为错误消息非常好。

In other words, I need to see the decision process in much more detail. For some reason this is not as needed with Guice, perhaps because there is much less magic, and perhaps because the error messages are very good.

你做什么来调试你的焊接应用程序,它有多大帮助?

What do you do to debug your Weld applications, and how much does it help?

推荐答案

简答:CDI没有专用的调试选项(因为没有规范要求这样的事情,并且Weld没有专用的调试选项。

Short answer: there is no dedicated debug option for CDI (as no such thing is required by the spec), and no dedicated debug option for Weld.

长答案:你可以自己做很多事情。熟悉CDI的扩展机制,你会发现你可以轻松(真的!)编写自己的扩展来调试你所需的信息

Long Answer: There is a lot you can do on your own. Familiarise yourself with the extension mechanism of CDI, and you'll discover that you can easily (really!) write your own extension that debugs your required information


什么扫描类路径条目,
在哪里?结果是什么?

What classpath entries are scanned and where? What was the result?

收听 ProcessAnnotatedType -Event


可以注入哪些bean
哪个类?

What beans are available for injection for which class?

查询BeanManager。

Query the BeanManager for that.


是什么导致给定的bean不是
以后考虑?一个给定的jar?

What caused a given bean not to be considered for later? A given jar?

收听 AfterBeanDiscovery -Event,看看你是什么已经进入了BeanManager。基本上,以下情况使ManageBean不符合注入条件:

Listen to the AfterBeanDiscovery-Event and see what you've got in the BeanManager. Basically, the following scenarios make a ManageBean ineligible for injection:

  • it's no ManagedBean (like there is no beans.xml in the jar)
  • it does not qualify as a managed bean (https://docs.jboss.org/weld/reference/1.1.0.Final/en-US/html/beanscdi.html#d0e794)
  • it has no BeanType (@Type{})
  • it is vetoed (Seam Solder) or suppressed by any other extension-mechanism

这篇关于Weld / CDI最好的调试技巧是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆