-
May 4th, 2007, 09:49 AM
#1
SEVERE: Context initialization failed
I'm getting the message:
SEVERE: Context initialization failed
on the console when I try to start my Spring application.
The next line of output is a null pointer exception caused by
WebApplicationContextUtils.getWebApplicationContex t returning a null.
The Tomcat log says essentially the same thing:
Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListe ner
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'InitManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException
If the problem is that Spring can't create my InitManager class, which the error msgs seem to imply, there is no indication of what failed. But the null pointer error occurs in one of the methods of the InitManager which would seem to indicate that it was created successfully.
On the other hand, if something else caused the context intialization to fail there is no information about the cause.
There is no other useful information in the output. How do I go about figuring out what has happened?
Thanks,
-=b
-
May 4th, 2007, 10:04 AM
#2
I have been looking at this problem for a while and I think it may be the result of the context simply not existing at the time I try to access it.
I'm trying to get the context in the afterPropertiesSet() method of a class that implemtents InitializingBean.
I removed the call to WebApplicationContextUtils.getWebApplicationContex t
and my class was created and the application started up.
After doing this when I look at the console output I see the following lines AFTER the point where I was seeing the context initialization failure message:
May 4, 2007 10:54:03 AM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Using context class [org.springframework.web.context.support.XmlWebAppl icationContext] for root WebApplicationContext
May 4, 2007 10:54:03 AM org.springframework.web.context.ContextLoader initWebApplicationContext
So it appears that there is no context at the point at which my afterPropertiesSet() method is called.
Does this seem reasonable? If so, is there an interface with something like an afterContextCreated() method?
Thanks,
-=b
-
May 4th, 2007, 10:23 AM
#3
I actually solved my own Spring problem, I must be getting the hang of things.
There is an interface to do what I needed. ApplicationContextAware has a method, setApplicationContext() that is called after the context is intialized.
In my case I was assuming that InitializingBean.afterPropertiesSet() was called after the context was initialized. However, it appears that it is not.
Thanks to all that would have replied,
-=b
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules