在一个Spring项目中,新建了一个外部属性文件db.properties,在xml文件中利用${}来引用db.properties文件里面的属性。

beans-properties.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-4.0.xsd"> <!-- 导入属性文件 -->
<context:property-placeholder location="classpath:db.properties"/> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<!-- 使用外部化属性文件的属性 -->
<property name="user" value="${user}"></property>
<property name="password" value="${password}"></property>
<property name="driverClass" value="${driverclass}"></property>
<property name="jdbcUrl" value="${jdbcurl}"></property>
</bean> </beans>

db.properties:

 user=root;
password=;
driverclass=com.mysql.jdbc.Driver;
jdbcurl=jdbc:mysql:///tt

Main.java:

 package com.tt.spring.beans.properties;

 import java.sql.SQLException;

 import javax.sql.DataSource;

 import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class Main { public static void main(String[] args) throws SQLException{ ApplicationContext ctx = new ClassPathXmlApplicationContext("beans-properties.xml"); DataSource dataSource = (DataSource) ctx.getBean("dataSource"); System.out.println(dataSource.getConnection()); }
}

lib目录如下:

运行Main.java代码,控制台打印信息如下:

原因分析:

如果直接在beans-properties.xml文件里对user,password,driverClass,jdbcUrl进行赋值,而不引用db.properties文件里的属性,运行正常。这说明服务器能加载到数据库驱动。

所以问题出在什么地方呢?

Spring警告: Could not load driverClass com.mysql.jdbc.Driver(待解决)的更多相关文章

  1. Could not load driverClass com.mysql.jdbc.Driver错误

    在整合spring和mybatis的时候,在spring配置文件中已经加载了db.properties并配置了c3p0数据源 但在写了一个测试类测试是否取到了数据库的连接时,报错:Could not ...

  2. 搭建jfinal框架时报 Could not load driverClass com.mysql.jdbc.Driver

    搭建jfinal框架时报 Could not load driverClass com.mysql.jdbc.Driver 没有加载MySQL的驱动,你有没有把mysql的驱动包放到你项目的WEB-I ...

  3. ssm框架找不到mysql驱动类WARN DriverManagerDataSource:107 - Could not load driverClass com.mysql.jdbc.Driver

    找了很久错误,检查了配置文件,和spring配置数据源,都没有发现问题,最后上网查询了下,发现是由于配置文件后面有空格. 去除掉配置文件后面的空格就可以正常运行了.

  4. powerdesigner连接MySQL数据库时出现Non SQL Error : Could not load class com.mysql.jdbc.Driver

    Non SQL Error : Could not load class com.mysql.jdbc.Driver 这是因为powerdesigner 无法找到驱动所产生的 解决办法是:配置系统的c ...

  5. PowerDesigner 逆向工程Non SQL Error : Could not load class com.mysql.jdbc.Driver

    建立与数据库的连接. 在菜单条上,有一个Database的选择项: 选择connect…后弹出设置对话框: 在Data source里选择第三个单选按钮,即Connection profile:后,点 ...

  6. cloudera-scm-server启动出现Error creating bean with name 'entityManagerFactoryBean'与HHH010003: JDBC Driver class not found: com.mysql.jdbc.Driver错误解决办法(图文详解)

    不多说,直接上干货! 问题详情 -- ::, INFO main:com.cloudera.server.cmf.Main: Starting SCM Server. JVM Args: [-Dlog ...

  7. 错误:“Cannot load JDBC driver class 'com.mysql.jdbc.Driver”的解决方法

    “Cannot load JDBC driver class 'com.mysql.jdbc.Driver ” 表示没有JDBC连接MySql的驱动包,因此需要手动添加驱动包到WEB-INF目录下的l ...

  8. IntelliJ IDEA web项目进行数据库连接时出现java.lang.ClassNotFoundException: com.mysql.jdbc.Driver错误解决办法

    首先看报错信息: 意思是找不到类:  com.mysql.jdbc.Driver.也就是说tomcat找不到MySQL数据库连接要用的jar包! 出现这种错误的原因是: 项目中没有导入这个jar包, ...

  9. Exception 02 : java.lang.ClassNotFoundException: Could not load requested class : com.mysql.jdbc.Driver

    异常名称 java.lang.ClassNotFoundException: Could not load requested class : com.mysql.jdbc.Driver 异常详细信息 ...

随机推荐

  1. FFmpeg 入门(4):线程分治

    本文转自:FFmpeg 入门(4):线程分治 | www.samirchen.com 概览 上一节教程中,我们使用 SDL 的音频相关的函数来支持音频播放.SDL 起了一个线程来在需要音频数据的时候去 ...

  2. [原创]css中a标签去掉锚点文本下划线

    我对博客的认识是:记录问题,解决问题,分享知识.如果有轮子,我不需要造轮子. 1.问题解决方式: 设置属性:text-decoration:none; 2.更多属性参数参考 text-decorati ...

  3. 20145331 《Java程序设计》第3周学习总结

    20145331 <Java程序设计>第3周学习总结 教材学习内容总结 第四章 认识对象 •对象(Object):存在的具体实体,具有明确的状态和行为 •类(Class):具有相同属性和行 ...

  4. Calling Convention的总结

    因为经常需要和不同的Calling Convention打交道,前段时间整理了一下它们之间的区别,如下: 清理堆栈 参数压栈顺序 命名规则 (MSVC++) 备注 Cdecl 调用者 (Caller) ...

  5. hadoop2对应的eclipse插件使用

    1. eclipse插件安装步骤: a).把插件复制到eclipse安装目录plugins文件夹下 b).打开eclipse的Window---Preference---Hadoop M/R---指向 ...

  6. Pomelo热更新刷新handler和remote 以及 pomelo使用bearcat进行热更新

    一. 开启 原生 pomelo 的hotreload支持 pomelo版本: 2.2.5 , 编辑脚本 app.js 加入如下代码 //全局配置 app.configure('production|d ...

  7. 爬虫之动态HTML处理(Selenium与PhantomJS )网站模拟登录

    #coding=utf-8from selenium import webdriverfrom selenium.webdriver.common.keys import Keysimport tim ...

  8. SSM框架下分页的实现(封装page.java和List<?>)

    之前写过一篇博客  java分页的实现(后台工具类和前台jsp页面),介绍了分页的原理. 今天整合了Spring和SpringMVC和MyBatis,做了增删改查和分页,之前的逻辑都写在了Servle ...

  9. 从0开始 数据结构 AC自动机 模板(from kkke)

    AC自动机模板 2.4.1 头文件&宏&全局变量 #include <queue> #define MAXN 666666 #define MAXK 26//字符数量 st ...

  10. caohaha's stuff

    2017-08-20 11:12:29 writer:pprpCCPC预选赛水平太菜了,去不了了 这个是一个找规律的题目,题意一开始也很难理解 题意描述: 给你一个数,比如说1,在一个坐标系中你需要用 ...