web mvc 正常。只是dao层方面。我只写了一个类,没有接口,只是想做一下简单连接。代码如下:
@Repository
public class TestDaoImp {
private JdbcTemplate jdbcTemplate;
@Autowired
public void setDataSource(@Qualifier(value="dataSource") DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
public void query() {
// TODO Auto-generated method stub
jdbcTemplate.queryForInt("select count(*) from bar_ip");
}
}
然后是xml配置:
<annotation-driven />
<context:component-scan base-package="sdf.dsf" />
<beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<beans:property name="driverClassName"><beans:value>com.mysql.jdbc.Driver</beans:value></beans:property>
<beans:property name="url"><beans:value>jdbc:mysql://localhost:3306/bar</beans:value></beans:property>
<beans:property name="username"><beans:value>root</beans:value></beans:property>
<beans:property name="password"><beans:value>125202505</beans:value></beans:property>
</beans:bean>
在TestDaoImp 的query()方法中的jdbcTemplate总是为null。。。不知道为什么。。
我是不是漏掉什么配置了???
繁花不似锦
繁星点点滴滴