0

Spring configuration problem: where to put the file ApplicationContext.xml

asked 2010-03-16 13:49:08 +0800

yuanbohan gravatar image yuanbohan
258 2 7

I am trying to integrate spring to my project, but there is always a problem existing. The hierarchy of my project is like this:

WebContent
.front/ (my own folder)
.images/(my own folder)
.META-INF/
.WEB-INF/
. lib/
. ApplicationContext.xml
. web.xml
. zk.xml
.index.zul

When I run the test.java(one of my java class to test if my configuration can connect to the database), the error appers at the following place:

ApplicationContext ctx;
static{
ctx = new ClassPathXmlApplicationContext("ApplicationContext.xml");
}


The error is:
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [ApplicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [ApplicationContext.xml] cannot be opened because it does not exist

iI have added the following codes into the web.xml.
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

Can anyone tell me where to put the "ApplicationContext.xml" into the right place? I have tried to use "WEB-INF/ApplicationContext.xml", "/WEB-INF/ApplicationContext.xml" and "/ApplicationContext.xml" to replace the ApplicationContext.xml in my codes, but the error is always existing. Help me!!!!

delete flag offensive retag edit

4 Replies

Sort by » oldest newest

answered 2010-03-16 15:25:51 +0800

YamilBracho gravatar image YamilBracho
1722 2

change to
ctx = new ClassPathXmlApplicationContext(Executions.getCurrent().getDesktop().getWebApp().getRealPath("/WEB-INF/"ApplicationContext.xml"));

link publish delete flag offensive edit

answered 2010-03-18 09:49:37 +0800

yuanbohan gravatar image yuanbohan
258 2 7

thanks. the way you teld me works, thank you!!! ^_^

link publish delete flag offensive edit

answered 2010-03-19 06:07:05 +0800

yuanbohan gravatar image yuanbohan
258 2 7

updated 2010-03-19 06:14:06 +0800

hi YamilBracho, I encounter a new problem. After I have used ZK form to connect to mysql database deri,
then the server cannot find the applicationContext.xml. The error information is:


2010-3-19 10:55:13 org.apache.catalina.core.AprLifecycleListener init
信息: Loaded APR based Apache Tomcat Native library 1.1.14.
2010-3-19 10:55:13 org.apache.catalina.core.AprLifecycleListener init
信息: APR capabilities: IPv6 , sendfile , accept filters , random .
2010-3-19 10:55:13 org.apache.coyote.http11.Http11AprProtocol init
信息: Initializing Coyote HTTP/1.1 on http-8080
2010-3-19 10:55:13 org.apache.coyote.ajp.AjpAprProtocol init
信息: Initializing Coyote AJP/1.3 on ajp-8009
2010-3-19 10:55:13 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 1091 ms
2010-3-19 10:55:13 org.apache.catalina.core.StandardService start
信息: Starting service Catalina
2010-3-19 10:55:13 org.apache.catalina.core.StandardEngine start
信息: Starting Servlet Engine: Apache Tomcat/6.0.20
2010-3-19 10:55:14 org.apache.catalina.core.ApplicationContext log
信息: Set web app root system property: 'webapp.root' = [D:\Program Files\Apache Software Foundation\Tomcat 6.0\wtpwebapps\deri\]
2010-3-19 10:55:14 org.apache.catalina.core.ApplicationContext log
信息: Initializing Log4J from [D:\Program Files\Apache Software Foundation\Tomcat 6.0\wtpwebapps\deri\WEB-INF\config\log4j.xml]
2010-3-19 10:55:15 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring root WebApplicationContext
2010-03-19 10:55:15,328 INFO ContextLoader M - Root WebApplicationContext: initialization started
2010-03-19 10:55:15,406 INFO XmlWebApplicationContext M - Refreshing org.springframework.web.context.support.XmlWebApplicationContext@10efd7c: display name [Root WebApplicationContext]; startup date [Fri Mar 19 10:55:15 GMT 2010]; root of context hierarchy
2010-03-19 10:55:15,531 INFO XmlBeanDefinitionReader M - Loading XML bean definitions from ServletContext resource [/WEB-INF/config/applicationContext.xml]
2010-03-19 10:55:15,859 INFO XmlWebApplicationContext M - Bean factory for application context [org.springframework.web.context.support.XmlWebApplicationContext@10efd7c]: org.springframework.beans.factory.support.DefaultListableBeanFactory@4bfe6b
2010-03-19 10:55:15,937 INFO DefaultListableBeanFactory M - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@4bfe6b: defining beans [deriDataSource,deriSessionFactory,sensorDao,sensorService]; root of factory hierarchy
2010-03-19 10:55:16,562 INFO LocalSessionFactoryBean M - Building new Hibernate SessionFactory
2010-03-19 10:55:17,640 INFO ContextLoader M - Root WebApplicationContext: initialization completed in 2297 ms
2010-3-19 10:55:17 org.zkoss.zk.ui.http.WebManager <init>:112
信息: Starting ZK 3.6.3 Enterprise (build: 09110309)
2010-3-19 10:55:17 org.zkoss.zk.ui.sys.ConfigParser parseConfigXml:127
信息: Loading system default
2010-3-19 10:55:17 org.zkoss.zk.ui.sys.ConfigParser parse:224
信息: Parsing jndi:/localhost/deri/WEB-INF/zk.xml
2010-3-19 10:55:20 org.apache.coyote.http11.Http11AprProtocol start
信息: Starting Coyote HTTP/1.1 on http-8080
2010-3-19 10:55:20 org.apache.coyote.ajp.AjpAprProtocol start
信息: Starting Coyote AJP/1.3 on ajp-8009
2010-3-19 10:55:20 org.apache.catalina.startup.Catalina start
信息: Server startup in 6404 ms
2010-03-19 10:55:21,750 INFO ClassPathXmlApplicationContext M - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@1292738: display name [org.springframework.context.support.ClassPathXmlApplicationContext@1292738]; startup date [Fri Mar 19 10:55:21 GMT 2010]; root of context hierarchy
2010-03-19 10:55:21,750 INFO XmlBeanDefinitionReader M - Loading XML bean definitions from class path resource [D:/Program Files/Apache Software Foundation/Tomcat 6.0/wtpwebapps/deri/WEB-INF/config/applicationContext.xml]
2010-3-19 10:55:21 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet zkLoader threw exception
java.io.FileNotFoundException: class path resource [D:/Program Files/Apache Software Foundation/Tomcat 6.0/wtpwebapps/deri/WEB-INF/config/applicationContext.xml] cannot be opened because it does not exist

at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:135)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:307)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:290)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:131)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:147)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:173)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:112)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:79)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:101)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:394)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:324)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:122)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:66)
at ie.deri.lion2.backend.util.ServiceLocator.<clinit>(ServiceLocator.java:15)
at ie.deri.lion2.backend.util.ListSensor.onCreate(ListSensor.java:14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.zkoss.zk.ui.impl.EventProcessor.process0(EventProcessor.java:209)
at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:141)
at org.zkoss.zk.ui.impl.UiEngineImpl.processEvent(UiEngineImpl.java:1461)
at org.zkoss.zk.ui.impl.UiEngineImpl.process(UiEngineImpl.java:1245)
at org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage0(UiEngineImpl.java:412)
at org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage(UiEngineImpl.java:299)
at org.zkoss.zk.ui.http.DHtmlLayoutServlet.process(DHtmlLayoutServlet.java:229)
at org.zkoss.zk.ui.http.DHtmlLayoutServlet.doGet(DHtmlLayoutServlet.java:165)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:574)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1527)
at java.lang.Thread.run(Unknown Source)


web.xml, ServiceLocator.java files are the followings:


//***************************web.xml***************************
...

<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/config/log4j.xml</param-value>
</context-param>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/applicationContext.xml</param-value>
</context-param>
...

//***************************serviceLocator.java***************************

...
public static ApplicationContext ctx;
static{
// ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
ctx = new ClassPathXmlApplicationContext(Executions.getCurrent().getDesktop().getWebApp().getRealPath("/WEB-INF/config/applicationContext.xml"));
}
...


From the information, I found that the server is looking for the applicationContext.xml file in the classpath, but it should be automatically created by the framework, for I have configured it in the web.xml file. Tomcat is installed at the D:/ disk, my project is running at the E:/ disk. And I have checked that the applicationContext.xml file does exist at that place : "D:/Program Files/Apache Software Foundation/Tomcat 6.0/wtpwebapps/deri/WEB-INF/config/applicationContext.xml"Can you help me with it??

link publish delete flag offensive edit

answered 2010-03-19 06:35:43 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2010-03-19 06:37:42 +0800

Hmmmmmmm, what do you do?

The server is well started with your configuration! Why you try to load the same configuration file double??

信息: Server startup in 6404 ms
2010-03-19 10:55:21,750 INFO ClassPathXmlApplicationContext M - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@1292738: display name [org.springframework.context.support.ClassPathXmlApplicationContext@1292738]; startup date [Fri Mar 19 10:55:21 GMT 2010]; root of context hierarchy
2010-03-19 10:55:21,750 INFO XmlBeanDefinitionReader M - Loading XML bean definitions from class path resource [D:/Program Files/Apache Software Foundation/Tomcat 6.0/wtpwebapps/deri/WEB-INF/config/applicationContext.xml]
2010-3-19 10:55:21 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet zkLoader threw exception
java.io.FileNotFoundException: class path resource [D:/Program Files/Apache Software Foundation/Tomcat 6.0/wtpwebapps/deri/WEB-INF/config/applicationContext.xml] cannot be opened because it does not exist

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2010-03-16 13:49:08 +0800

Seen: 3,121 times

Last updated: Mar 19 '10

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More