Spring和Mybatis框架整合无法识别jdbc.properties文件

在把数据库配置文件写到jdbc.properties文件中后试图在applicationContext.xml中用${property}的方式来读取属性值,但是始终报错spring无法识别jdbc.properties文件,报错信息如下

org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: class path resource [jdbc.properties] cannot be opened because it does not exist

首先怀疑是引用jdbc.properties的bean标签写错了

    <context:property-placeholder location="classpath:jdbc.properties" />

确定没有问题,最后找到了问题原因是pom.xml只设定了读取resource目录下.xml文件,导致编译时默认.properties文件被忽略

 

 

解决方法:

在maven配置文件pom.xml的resources标签中加入如下代码

            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.properties</include>
                </includes>
            </resource>

系统在编译时不会忽略.properties文件了

 

posted @ 2021-04-02 16:47  Carln  阅读(2022)  评论(0)    收藏  举报