Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Spring MVC problem

  Asked By: Meenachi    Date: Jun 25    Category: Java    Views: 2036
  

i have error to define 2 seperate Spring XML config files in web.xml that cuase error .


my web.xml files is :


<web-app>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListe ner
</listener-class>
</listener>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/config/spring/mvc-controllers.xml
,/WEB-INF/config/spring/mvc-setting.xml
</param-value>
</context-param>


<servlet>
<servlet-name>mymvc</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping >
<servlet-name>mymvc</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
</web-app >
*******************
my two xml files is exist and if i rename it to wrong names my tomcat 5.5 get me error that cann't find these files , so this files is be found bye spring listener with true name and path.

but Although i setup 2 files for spring listener , spring context still try to find default spring config file in /WEB-INF/mymvc-servlet.xml !!! with this error on start up (my stack trace) :

[ERROR] 14:28:28 DispatcherServlet - Context initialization failed
org.springframework.beans.factory.BeanDefinitionSt oreException: IOException parsing XML document from ServletContext resource [/WEB-INF/mymvc-servlet.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/mymvc-servlet.xml]
java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/mymvc-servlet.xml]
at org.springframework.web.context.support.ServletCon textResource.getInputStream(ServletContextResource .java:99)
at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.loadBeanDefinitions(XmlBeanDefinitionR eader.java:167)
at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.loadBeanDefinitions(XmlBeanDefinitionR eader.java:148)
at org.springframework.beans.factory.support.Abstract BeanDefinitionReader.loadBeanDefinitions(AbstractB eanDefinitionReader.java:129)
at org.springframework.beans.factory.support.Abstract BeanDefinitionReader.loadBeanDefinitions(AbstractB eanDefinitionReader.java:145)
at org.springframework.web.context.support.XmlWebAppl icationContext.loadBeanDefinitions(XmlWebApplicati onContext.java:126)
at org.springframework.web.context.support.XmlWebAppl icationContext.loadBeanDefinitions(XmlWebApplicati onContext.java:94)
at org.springframework.context.support.AbstractRefres hableApplicationContext.refreshBeanFactory(Abstrac tRefreshableApplicationContext.java:89)
at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:262)
at org.springframework.web.context.support.AbstractRe freshableWebApplicationContext.refresh(AbstractRef reshableWebApplicationContext.java:139)
at org.springframework.web.servlet.FrameworkServlet.c reateWebApplicationContext(FrameworkServlet.java:3 06)
at org.springframework.web.servlet.FrameworkServlet.i nitWebApplicationContext(FrameworkServlet.java:251 )
at org.springframework.web.servlet.FrameworkServlet.i nitServletBean(FrameworkServlet.java:220)
at org.springframework.web.servlet.HttpServletBean.in it(HttpServletBean.java:112)
at javax.servlet.GenericServlet.init(GenericServlet.j ava:211)
at org.apache.catalina.core.StandardWrapper.loadServl et(StandardWrapper.java:1003)
at org.apache.catalina.core.StandardWrapper.load(Stan dardWrapper.java:836)
at org.apache.catalina.core.StandardContext.loadOnSta rtup(StandardContext.java:3823)
at org.apache.catalina.core.StandardContext.start(Sta ndardContext.java:4128)
at org.apache.catalina.startup.HostConfig.checkResour ces(HostConfig.java:1044)
at org.apache.catalina.startup.HostConfig.check(HostC onfig.java:1136)
at org.apache.catalina.startup.HostConfig.lifecycleEv ent(HostConfig.java:292)
at org.apache.catalina.util.LifecycleSupport.fireLife cycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.StandardHost.backgroundPr ocess(StandardHost.java:729)
at org.apache.catalina.core.ContainerBase$ContainerBa ckgroundProcessor.processChildren(ContainerBase.ja va:1511)
at org.apache.catalina.core.ContainerBase$ContainerBa ckgroundProcessor.processChildren(ContainerBase.ja va:1520)
at org.apache.catalina.core.ContainerBase$ContainerBa ckgroundProcessor.run(ContainerBase.java:1500)
at java.lang.Thread.run(Thread.java:595)

please help me if you have idea about my problem
note : use servlet or listener didn't help me to solve this problem.

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Francis Riley     Answered On: Jun 25

This is what I think that works for you presuming that the files  exist.


<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/config/spring/mvc-controllers.xml
/WEB-INF/config/spring/mvc-setting.xml
</param-value>
</context-param>

and this one as well:

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/config/spring/mvc*.xml
</param-value>
</context-param>

Meanwhile spring  normally looks for ${your-servlet}-servlet.xml as the default  applicationContext.xml. That is what your error  was all about. Another option is to put your context  files in classpath and declare them in this way:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:/applicationContext-hibernate.xml
classpath:/applicationContext-services.xml
classpath:/applicationContext-dao.xml
classpath:/applicationContext-core.xml
...
</param-value>
</context-param>

Moreover, There is an import mechanism that spring teams recommends to use to import all your context files (http://www.springframework.org/docs/reference/beans.html#beans-basics , part 3.18). Using the technique, you just declare one xml  file (or use the default and declare nothing in web.xml) and import other context files in such a way :
<beans>

<import resource="services.xml"/>

<import resource="resources/messageSource.xml"/>

<import resource="/resources/themeSource.xml"/>

<bean id="bean1" class="..."/>

<bean id="bean2" class="..."/>
. . .
</beans>

 
Didn't find what you were looking for? Find more on Spring MVC problem Or get search suggestion and latest updates.




Tagged: