日期:2014-05-18 浏览次数:20674 次
//spring 配置
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/cdb" />
<property name="user" value="root"/>
<property name="password" value="123456"/>
</bean>
<bean id="cpaction" class="com.fw.ls.cp.action.CpAction">
<property name="dataSource" ref="dataSource"></property>
</bean>
//CpAction
private DataSource dataSource;
public String add(){
JdbcTemplate jt = new JdbcTemplate(dataSource);
String sql = "insert into cp(id,xuhao,dianhua)values(id,?,?)";
jt.update(sql,"casc","1212");
return SUCCESS;
}
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
}
//错误代码
java.lang.IllegalArgumentException: Property 'dataSource' is required
setDataSource(DataSource dataSource)并没有进入这个方法就报错了