Improve exception when failing to create a specific bean due to a NoClassDefFoundError [SPR-14883] #19449
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
type: enhancement
A general enhancement
Milestone
Antonio Anzivino opened SPR-14883 and commented
I am currently stuck in determining the cause of a NoClassDefFoundError that is occurring in my project.
I am reporting this ticket to request an improvement, and to discuss how it should be implemented.
My specific problem (which I can't diagnose on my own) is a NoClassDefFoundError
From my understanding, some bean contains an
@Autowired
dependency for which the autowired bean contains a constructor dependency with WebJarAssertLocator. I am not willing to inlude WebJarAssetLocator in my classpath, I need to identify the component dependent to that class in order to remove its dependency from webjars package.Now the problem is that this stack trace does not provide information on what bean caused the failure. I could get more information if I had either the name of the bean that contains the faulty
@Autowired
definition or else the name of the bean that is faulty to instantiate as an@Autowired
bean.My proposal is for Spring Framework to increase the number of catch(Throwable) statements, and log little extra contextual information when these Throwables occur.
A simple, but probably insufficient and too simplicistic, proposal for which I could create a PR easily, is to wrap the entire doGetBean method in the following:
Another alternate proposal, that follows a pattern I like a lot to apply, is the following (DefaultListableBeanFactory#731):
The pattern is: when performing a loop, identify the element that caused an exception and throw its identifying information in a new exception that wraps the cause. This helps diagnosis.
This is meant to provide discussion and improvement. I will have to debug my specific error on my own, but I would like to see this (especially the second pattern) implemented in future releases
Affects: 4.3.3
Issue Links:
Referenced from: commits c44c607, cf479bf, b3cd1ad, b42d731, 3d2e4c3, 37f4f43
The text was updated successfully, but these errors were encountered: