tomcatAbstractApplicationContext prepareRefresh Spring刷新问题
在使用Spring过程中,从tomcat后台日志发现总是去刷新applicationContext.xml文件。由于applicationContext.xml按作用差分成多个放在classpath下的spring文件夹下,又导致再刷新的时候报错。
2013-6-26 15:23:06 org.springframework.context.support.AbstractApplicationContext prepareRefresh信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@712801c5: startup date [Wed Jun 26 15:23:06 CST 2013]; root of context hierarchy2013-6-26 15:23:06 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions信息: Loading XML bean definitions from class path resource [applicationContext.xml]2013-6-26 15:23:06 org.apache.catalina.core.ApplicationDispatcher invoke严重: Servlet.service() for servlet jsp threw exceptionjava.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not existat org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:157)at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328)at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:243)at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131)at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:530)at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:444)at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
解决方法:1.在运行过程中spring应该是不会自动去刷新applicationContext.xml的,怀疑应该是哪里使用了配置进行刷新。
? ? ? ? ? ? ? ? ? ? ?2.发现在action中我有直接使用Configuration.getXXX()去获取某个bean,通过它去获取bean的时候就会刷新,由于Configuration没有指定applicationContext.xml路径,所以默认到classpath下读取applicationContext.xml