Spring配置c3p0时报错。没看懂是什么原因.请大家帮忙
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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 http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd "> <!-- 数据源 --> <bean id="datasourceId" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name=" driverClass" value="com.mysql.jdbc.Driver"/> <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/test"/> <property name="user" value="root"/> <property name="password" value="000000"/> </bean> <!-- 创建模板 --> <bean id="JdbcTemplateId" class="org.springframework.jdbc.jdbc.core.JdbcTemplate"> <property name="datasource" ref="datasourceId"/> </bean> <bean id="UserId" class="com.dao.UserDao"> <property name="JdbcTemplate" ref="JdbcTemplate"/> </bean></beans>
以上是xml文件
以下为Dao文件
public class UserDao { private JdbcTemplate jdbc; public void setJdbc(JdbcTemplate jdbc) { this.jdbc = jdbc; } public void update(User user){ String sql = "update t_user set userName=?,passWord=? where id=?"; Object[] args = {user.getId(),user.getUserName(),user.getPassWord()}; jdbc.update(sql, args); } }
测试如下:
public class App { public static void main(String[] args) { User user = new User(); user.setId(1); user.setUserName("jr"); user.setPassWord("1234"); ApplicationContext ac = new ClassPathXmlApplicationContext("bean.xml"); UserDao userDao = (UserDao) ac.getBean("UserId"); userDao.update(user); } }
jar包如下: