三大框架如何的测试?
该项目是可以运行的,但是我想测试一下方法是否可以使用。
1、建立测试包下的类
public class test {
public static void main(String[] args) {
TbStudent s=new TbStudent();
s.setName("2");
s.setPwd("1234");
StudentBiz st=new StudentBiz();
st.add(s); //运行到这里报错
}
报错信息如下
Exception in thread "main" java.lang.NullPointerException
at com.student.biz.StudentBiz.add(StudentBiz.java:27)
at com.test.test.main(test.java:14)
StudentBiz类的关键代码
//建立数据访问层对象
private IStudentDao udao ; //报错:觉得跟依赖注入有关系
//依赖注入时调用
public void setUdao(IStudentDao udao) {
this.udao = udao;
}
public boolean add(TbStudent user) {
return udao.add(user);
}
spring配置文件:
<!-- Spring 集成hibernate -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>
<!-- 数据访问层 -->
<bean id="studentDao" class="com.student.dao.SutdentDao">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 业务逻辑层 -->
<bean id="ubiz" class="com.student.biz.StudentBiz">
<property name="udao" ref="studentDao"></property>
</bean>
问题:怎么修改才可以让测试成功运行?