I have a large Spring 2.x-based application with a couple of hundreds of applicationContext.xml
files and several thousands beans/bean factories.
Most of these XML configurations say something like default-autowire="byName"
, effectively turning on the autowiring, but only a fraction of beans is actually autowired. Most of the bean properties are set explicitly.
(This is to historical reasons, I guess that's how you call it when you were not clever enough in the past.)
Now we would like to remove autowiring at all. We believe that only a small fraction of beans is actually autowired - but we do not know, what and were exactly. My question is:
How can we find out what and were exactly is autowired by Spring?
Ideally, we need to get a list of beans/properties so that we could inject these explicitly in out XML configurations. But before diving into Spring internals with a debugger, I decided to ask if someone on SF has maybe already solved a similar task.
ps. I don't have an intention to discuss whether autowiring is good or bad. We have a number of internal technical reasons to remove autowiring, that's all.
Spring @Autowired Annotation - Service ClassThe setter method will be used for spring autowiring byName and byType whereas constructor based injection will be used by constructor autowire attribute.
Autowiring by autodetect uses either of two modes i.e. constructor or byType modes. First it will try to look for valid constructor with arguments, If found the constructor mode is chosen. If there is no constructor defined in bean, or explicit default no-args constructor is present, the autowire byType mode is chosen.
Autowiring 'byType': This option enables the autowire based on bean type. It searches the property's class type in the configuration file. It injects the property if such bean is found; otherwise, an error is raised.
The default autowire mode in java configuration is byType .
You can try to enable DEBUG logging in Spring. It prints a lot of information during initialisation phase. I bet auto-wiring messages are also printed out. You just need to find that message and then parse the log file after application is fully initialised.
UPDATE: I believe AbstractAutowireCapableBeanFactory is responsible for auto-wiring logic. You can check autowireByName method. It produces the following log message which you can search for in the log file:
logger.debug("Added autowiring by name from bean name '" + beanName +
"' via property '" + propertyName + "' to bean named '" + propertyName + "'");
My guess would be to enable a logger (log4j
) for that package (the one which does autowire) in a specific file.
That would output the name of all of the beans.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With