三大框架如何的测试?

qq_34016767 2016-06-18 09:49:47
该项目是可以运行的,但是我想测试一下方法是否可以使用。
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
>

问题:怎么修改才可以让测试成功运行?
...全文
186 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
今天晴 2016-06-20
  • 打赏
  • 举报
回复
st.add(s)编译通过了?
caogang_90 2016-06-20
  • 打赏
  • 举报
回复
StudentBiz st=new StudentBiz(); 这个service不能New 应该是ApplicationContext ctx = new ClassPathXmlApplicationContext("spring_config.xml"); StudentBiz studentBiz= (GetExpertUnit) ctx.getBean("studentBiz" ,StudentBiz.class);
阳光越来越暖 2016-06-18
  • 打赏
  • 举报
回复
链接:http://pan.baidu.com/s/1hrIim5u 密码:uen0 这是我写的一个基本的三大框架测试 你看看嘛

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧