如何在使用Spring IoC时跟踪所有@Autowired东西? [英] How to keep track of all the @Autowired stuff while using Spring IoC?
问题描述
在 Spring @Autowired用法问题中,大多数人回答说,他们宁愿不使用配置文件,如果可能的.乍一看似乎是一个不错的答案.
On Spring @Autowired usage question most of the people answer they prefer not using configuration files, if possible. It seems like a good answer at the first glance.
但是,一旦有了一个使用Spring IoC的大型应用程序并使用@ Autowired,@ Service等批注将所有东西自动装配起来,就必须解决这个问题:您将不再能够跟踪bean的依赖关系.
你怎么处理?
However, once you have quite a big application which uses Spring IoC and autowires all the stuff using annotations @Autowired, @Service, etc. you must hit this problem: you no longer are able to keep track of your bean dependencies.
How do you deal with that?
使用SpringSource Tool Suite可以基于配置文件创建依赖关系图.
有没有与@Autowired东西相同的工具? (我知道图形必须在运行时创建).
Using SpringSource Tool Suite one can create graphs of dependencies on the basis of configuration files.
Is there any tool out there which does the same with @Autowired stuff? (I understand graphs would have to be created on runtime).
推荐答案
实施BeanFactoryAware,并将传递给setBeanFactory()的工厂转换为
Implement BeanFactoryAware and cast the factory that is passed into setBeanFactory() to a DefaultListableBeanFactory. Then use DefaultListableBeanFactory.getBeanDefinitionNames() and DefaultListableBeanFactory.getDependenciesForBean() to generate the dependency graph.
这篇关于如何在使用Spring IoC时跟踪所有@Autowired东西?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!