//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)并没有进入这个方法就报错了
spring?jdbc spring jdbc
------解决方案--------------------
还有Struts吧
看下这个帖子6楼的回答
希望对你有帮助