PDA

View Full Version : No WebApplicationContext found: no ContextLoaderListener registered?


kuzman
Mar 21st, 2006, 07:14 AM
I am working on an application that has used spring for a while to create
remote proxies for EJBs and used acegi for security. I am starting to convert
the struts to use DelegatingActionProxy. I have added the proper configuration
to my struts-config.xml file and have added the bean definitions to my spring
configuration. The good news is that the application is working well. The
delegate passes the request to my action and the remote proxies are injected
into the action. The bad news is that my MockStrutsTestCases are all failing
with the following error:

[ERROR,ContextLoaderPlugIn,main] Context initialization failed
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name '/ClaimEmployeeList' defined in ServletContext resource [/WEB-INF/conf/claims-servlet.xml]: Initialization of bean failed; nested exception is java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
at org.springframework.web.context.support.WebApplica tionContextUtils.getRequiredWebApplicationContext( WebApplicationContextUtils.java:83)
at org.springframework.web.struts.DispatchActionSuppo rt.initWebApplicationContext(DispatchActionSupport .java:102)
at org.springframework.web.struts.DispatchActionSuppo rt.setServlet(DispatchActionSupport.java:78)

...

I do have ContextLoaderListener defined in my web.xml with a corresponding
contextConfigLocation context-param. What have I missed?

-Jeff

dgynn
Mar 21st, 2006, 10:57 AM
The MockStrutsTestCase simulates a servlet container but doesn't simulate it completely. It probably isn't simulating the loading of Listeners. I haven't used MockStrutsTestCase but I think you would need to extend it to handle the creation of the Spring application context.

kuzman
Mar 21st, 2006, 12:33 PM
The MockStrutsTestCase simulates a servlet container but doesn't simulate it completely. It probably isn't simulating the loading of Listeners. I haven't used MockStrutsTestCase but I think you would need to extend it to handle the creation of the Spring application context.

What would be the best way to create this context?

kuzman
Mar 21st, 2006, 01:37 PM
I resolved the issue by adding the following to my base test class setUp method:

context.setInitParameter(ContextLoader.CONFIG_LOCA TION_PARAM,
getContextDirectory() + SPRING_CONTEXT_FILE_LOCATION);
new ContextLoader().initWebApplicationContext(context) ;


I hope others find this useful.

-Jeff

netzone_tech
Apr 6th, 2006, 09:51 PM
Thank you!

You have saved me.. I've been banging my head against this desk for the past 2 hours. :rolleyes: