We have a (non-web app) Spring application that throws a NoSuchBeanDefinitionException when running tests on our CruiseControl continuous integration linux box. The test runs fine on Windows in Eclipse.
The exception is thrown on the getBean() method:
ApplicationContext context = new ClassPathXmlApplicationContext(CONTEXT_FILE);
MyBean bean = (MyBean)context.getBean("myBean");
The context file is rather large and complicated. The context file is in the classpath and Spring is finding it. I'd prefer it if Spring would throw an exception when trying to load the context file and build the dependencies so that we could have an idea as to where to start. Is there a way to force Spring to throw an exception at the time of creating the context?
Solved. The instantiation of "myBean" in CONTEXT_FILE occurred after another bean that depended on it. This really should not be an issue, but I suspect that the parser on the Linux box must be stricter. Anyway, changing the order of definitions made it work on both Windows and Linux.
Are you certain that there is a bean named "myBean" in the CONTEXT_FILE? Are you using more than one context file? Have you turned up the Spring's logging to verify that the CONTEXT_FILE is being loaded correctly, and furthermore, than the file Spring is loading from the classpath is the exact file you think it should be loading?
I think you might be looking for the wrong solution to your problem - I've never seen Spring throw a NoSuchBeanDefinitionException except for the case where the bean you are asking for is not defined in the context, simple as that.
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