提示:
日志打印Loading XML bean definitions from class path resource [applicationContext.xml]一般是获取applicationContext.xml失败。
例:
applicationContext.xml所在位置如下(左),service写一个save()方法。applicationContext.xml配置内容省略...
写个@Test测试类通过ClassPathXmlApplicationContext获取spring的配置文件applicationContext.xml 。
运行项目失败(什么也没打印出来),日志提示:
[org.springframework.beans.factory.xml.XmlBeanDefinitionReader]-[INFO] Loading XML bean definitions from class path resource [applicationContext.xml]
全部日志:
2019-12-19 14:53:32,285 [main] [org.springframework.core.env.StandardEnvironment]-[DEBUG] Adding [systemProperties] PropertySource with lowest search precedence
2019-12-19 14:53:32,289 [main] [org.springframework.core.env.StandardEnvironment]-[DEBUG] Adding [systemEnvironment] PropertySource with lowest search precedence
2019-12-19 14:53:32,289 [main] [org.springframework.core.env.StandardEnvironment]-[DEBUG] Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
2019-12-19 14:53:32,293 [main] [org.springframework.context.support.ClassPathXmlApplicationContext]-[INFO] Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@40b73194: startup date [Thu Dec 19 14:53:32 CST 2019]; root of context hierarchy
2019-12-19 14:53:32,346 [main] [org.springframework.core.env.StandardEnvironment]-[DEBUG] Adding [systemProperties] PropertySource with lowest search precedence
2019-12-19 14:53:32,346 [main] [org.springframework.core.env.StandardEnvironment]-[DEBUG] Adding [systemEnvironment] PropertySource with lowest search precedence
2019-12-19 14:53:32,347 [main] [org.springframework.core.env.StandardEnvironment]-[DEBUG] Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
2019-12-19 14:53:32,369 [main] [org.springframework.beans.factory.xml.XmlBeanDefinitionReader]-[INFO] Loading XML bean definitions from class path resource [applicationContext.xml]
我这运行失败原因是: applicationContext.xml放在src/main/resources/spring 目录下,获取applicationContext.xml配置文件的时候前边没有加spring目录。加上spring/后项目正常运行了。