I am sorry that this is probably too vague and generel of a question. I am trying to bring up a huge legacy project with tons of spring wirings, and I am getting this error:
The bizzare thing is this error does not tell me on which xml, which bean id, the error occurs.
I certainly don't expect anybody to point me to where to fix.. My question is, how do spring experts even debug this kind of uninformative error message?
Yes, I understand it must be one of my xml bean was set wrongly. But shouldn't the error message make it easier for me to find out which bean?
Any advice would be extremely appreciated.
00:09:00.640 [main] ERROR com.xxxx.yyyy.zzzzzz.AppMain - Failed to initialize BLAH BLAH BLAH
java.lang.IllegalStateException: No bean class specified on bean definition
at org.springframework.beans.factory.support.AbstractBeanDefinition.getBeanClass(AbstractBeanDefinition.java:381) ~[spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:154) ~[spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1035) ~[spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:939) ~[spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485) ~[spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) ~[spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]
It's thrown by following piece of code. The init() methods takes in the spring xml files and do its wiring.
try {
AppMain.init(args_);
} catch (Exception e) {
_LOGGER.error("Failed to initialize BLAH BLAH BLAH", e);
System.exit(-1);
}
That's a piece of the sources where it fails You can try to set a breakpoint there in the Exception throwing. Or add the spring code rather than jar file and try to debug there.
public Class<?> getBeanClass() throws IllegalStateException {
Object beanClassObject = this.beanClass;
if (beanClassObject == null) {
throw new IllegalStateException("No bean class specified on bean definition");
}
if (!(beanClassObject instanceof Class)) {
throw new IllegalStateException(
"Bean class name [" + beanClassObject + "] has not been resolved into an actual Class");
}
return (Class) beanClassObject;
}
My question is, how do spring experts even debug this kind of uninformative error message?
I'd argue that the error message is very informative. It states that something has tried to put your application in an illegal state. In this particular example, your context was configured in a way where some bean's class is not specified. This is typically caused by forgetting to put a class
attribute in a <bean>
declaration.
Spring creates BeanDefinition
objects for each bean in your context. These can be from your <bean>
declarations or other XML elements or Java configuration elements (from @Configuration
, @Component
, etc.). Almost everything involved in a Spring ApplicationContext
is a bean.
You can be pretty sure that Spring's infrastructure beans aren't to blame for this. Spring is an established framework with tons of work put into it and testing done before every release. The immediately obvious alternative is that somewhere in your code you forgot to specify a class
. Did you, for example, try to make an abstract
<bean>
but forget to add the abstract="true"
? Did you register a BeanDefinitionParser
and create BeanDefinition
s without a class
? Did you create BeanDefinitionPostProcessor
and remove BeanDefinition
class
values?
Those are the things I would start with.
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