druid.properties找不到 大lao进来看看吧

测试代码

public class JdbcTest {
    public static void main(String[] args) {
        ClassPathXmlApplicationContext app = new ClassPathXmlApplicationContext("applicationContext.xml");
        JdbcTemplate jdbcTemplate = (JdbcTemplate) app.getBean("jdbcTemplate");
        List<Map<String, Object>> maps = jdbcTemplate.queryForList("select * from user_01");
        System.out.println(maps);
    }
}

 

applicationcontext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
                             ">


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

    <!--   数据源Datasource -->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
        <property name="driverClassName" value="${driverClassName}"/>
        <property name="url" value="${druid.url}"/>
        <property name="username" value="${druid.username}"/>
        <property name="password" value="${druid.password}"/>
    </bean>

    <!--    创建JDBCTemple对象-->
    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource" ref="dataSource"/>
    </bean>


</beans>

 

报错

 Could not load properties; nested exception is java.io.FileNotFoundException: class path resource [druid.properties] cannot be opened because it does not exist

 

重新编译一下然后再启动

我去,我重新创建了一个properties文件。内容相同,没想到就加载成功了。。。。。。。