How to keep track of all the @Autowired stuff while using Spring IoC?

杀马特。学长 韩版系。学妹 提交于 2019-12-06 06:42:28

问题


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.

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?

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).


回答1:


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.



来源:https://stackoverflow.com/questions/5850639/how-to-keep-track-of-all-the-autowired-stuff-while-using-spring-ioc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!