《Maven精品教程视频\day02视频\03ssh配置文件加载过程.avi;》

此课程中讲 SSH三大框架整合的加载流程,还可以,初步接触的朋友可以听一听。

\day02视频\04ssh整合-struts2跟spring框架整合.avi;
\day02视频\04ssh整合-分别搭建环境.avi;
\day02视频\06ssh整合-spring跟Hibernate框架整合.avi;
\day02视频\07ssh整合功能案例实现.avi;

》 这几节课都可以听,可以快速了解一下 shh的搭建。

-------------测试 每个模块都测试

DAO模块中
也可以写测试,选中某个单元文件,右键创建 Junit测试单元,选择放在 test 目录  下面是注解方式

有必要重复听,看看Test中是如何实现 自动注入对象的,之前本人测试时碰到不可以注入。

import static org.junit.Assert.*;importorg.junit.Test;importorg.junit.runner.RunWith;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.test.context.ContextConfiguration;importorg.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.
class)
@ContextConfiguration(
"classpath:spring/applicationContext-*.xml")public classCustomerDaoTest {

@Autowired
privateCustomerDao dao;

@Test
public voidtestFindOne() {
dao.findOne(
"1");
}

在service 模块
写测试??  可以写。  下面是手动加载bean方式。

classpath*:spring/applicationContext-*.xml  第一个*指加载不仅仅当前 classpath(可以其他模块jar包的classpath), 第二*通配符。
@Testpublic voidtestFindOne() {
ClassPathXmlApplicationContext classPathXmlApplicationContext
= new ClassPathXmlApplicationContext("classpath*:spring/applicationContext-*.xml");
CustomerService service
= (CustomerService) classPathXmlApplicationContext.getBean("customerService");
service.findOne(
"1");
}

标签: none

添加新评论