//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)并没有进入这个方法就报错了
------ Solution ------------------------------------- -------
there Struts bar
facie 6F answer this post
I hope to help you
没有评论:
发表评论