SOA服务架构——class path resource [resource/db.properties] cannot be opened because it does not (penguin)

严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: class path resource [resource/db.properties] cannot be opened because it does not exist
    at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.postProcessBeanFactory(PropertySourcesPlaceholderConfigurer.java:151)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:265)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:162)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:606)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:462)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)

 

 

=================================================================================

Caused by: java.io.FileNotFoundException: class path resource [resource/db.properties] cannot be opened because it does not exist
    at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172)
    at org.springframework.core.io.support.EncodedResource.getInputStream(EncodedResource.java:143)
    at org.springframework.core.io.support.PropertiesLoaderUtils.fillProperties(PropertiesLoaderUtils.java:98)
    at org.springframework.core.io.support.PropertiesLoaderSupport.loadProperties(PropertiesLoaderSupport.java:175)
    at org.springframework.core.io.support.PropertiesLoaderSupport.mergeProperties(PropertiesLoaderSupport.java:156)
    at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.postProcessBeanFactory(PropertySourcesPlaceholderConfigurer.java:142)
    ... 16 more

============================================================

对于这个错误:

=============================

修改applicationContext-*.xml文件:


    

修改完之后:


    

=================================

为什么这么改?

==================================================

1.因为eclipse中Package Explorer的目录结构:

/milk-management-service
/milk-management-service/src/main/java
com.milk.service.impl
/milk-management-service/src/main/java/com/milk/service/impl/ItemCatServiceimpl.java
/milk-management-service/src/main/java/com/milk/service/impl/ItemServiceImpl.java
/milk-management-service/src/main/resources
/milk-management-service/src/main/resources/conf
/milk-management-service/src/main/resources/conf/client.conf
/milk-management-service/src/main/resources/conf/db.properties
/milk-management-service/src/main/resources/conf/resource.properties
/milk-management-service/src/main/resources/mybatis
/milk-management-service/src/main/resources/mybatis/SqlMapConfig.xml
/milk-management-service/src/main/resources/spring
/milk-management-service/src/main/resources/spring/applicationContext-dao.xml
/milk-management-service/src/main/resources/spring/applicationContext-service.xml
/milk-management-service/src/main/resources/spring/applicationContext-trans.xml
/milk-management-service/src/test/java
/milk-management-service/src/test/resources
/milk-management-service/src
/milk-management-service/src/main
/milk-management-service/src/main/webapp
/milk-management-service/src/main/webapp/WEB-INF
/milk-management-service/src/main/webapp/WEB-INF/web.xml
/milk-management-service/src/test
/milk-management-service/target

===========================================

项目的加载顺序是:先进入service模块web.xml去寻找:


        contextConfigLocation
        classpath:spring/applicationContext-*.xml

=================

再去根据路径去进入spring/applicationContext-*.xml,、

============================

然后,在spring/applicationContext-dao.xml中找到


    

看这个路径有没有配错,按这个路径去寻找一个叫做db.properties的文件,看路径错没错。

 

你可能感兴趣的:(SOA服务架构——class path resource [resource/db.properties] cannot be opened because it does not (penguin))