sql2005数据库
<bean id="Source" class="org.apache.commons.dbcp.BasicDataSource" >
<property name="driverClassName">
<value>com.microsoft.sqlserver.jdbc.SQLServerDriver</value>
</property>
<property name="url">
<value>jdbc:sqlserver://localhost:1433;DatabaseName=zyc_book</value>
</property>
<property name="username">
<value>sa</value>
</property>
<property name="password">
<value></value></property>
</bean>
<bean id="TestDAO" class="zyc.TestDAO">
<property name="dataSource">
<ref local="Source"/>
</property>
</bean><bean id="testAction" class="zyc.TestAction">
<property name="commandClass">
<value>zyc.TestForm</value>
</property>
<property name="validator">
<ref local="testValidator" />
</property>
<property name="testDao"> 
<ref local="TestDAO"/>
</property>
<property name="formView">
<value>register</value>
</property>
<property name="successView">
<value>success</value>
</property>
</bean>package zyc;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;public class TestAction extends SimpleFormController {
private TestDAO testDao;
protected ModelAndView onSubmit(HttpServletRequest request,HttpServletResponse response,Object command,BindException errors) throws Exception{
TestForm testForm=(TestForm)command;
testDao=this.getTestDao();
if(testDao==null)
System.out.print("\n\n\n\n\ntest  null\n\n\n");  //这里注入成功
if(testDao.isExist(testForm.getUsername()))
return new ModelAndView(this.getSuccessView());
else
return new ModelAndView(this.getFormView());


}
public TestDAO getTestDao() {
return testDao;
}
public void setTestDao(TestDAO testDao) {
this.testDao = testDao;
}
}
package zyc;import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;import javax.sql.DataSource;import org.apache.commons.dbcp.BasicDataSource;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;public class TestDAO {
private DataSource dataSource;public DataSource getDataSource() {
return dataSource;
}public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
}
public boolean isExist(String username){
if(this.getDataSource()==null)
{ System.out.print("\n\n\nnull\n\n\n");//这里得到空,注入失败
return true;
}
JdbcTemplate jdbcTemplate=new JdbcTemplate(getDataSource());
 int count=jdbcTemplate.queryForInt("select count(*) from book_user where user_name='"+username+"'"); 
if(count>0)
return false;
else
   return true; 
}
}testDAO 注入到testAction能注入成功
dataSource 注入到testDAO不成功。为啥?