Junit 调用Spring XML资源文件的方式
来源:互联网 发布:中电四公司知乎 编辑:程序博客网 时间:2024/06/06 05:09
/**
* Test User Service
* @author Shawn xiao
* @version 2017-06-15
*/
@RunWith(SpringJUnit4ClassRunner.class)
// Method 1: use the annotation @ContextConfiguration and call XMl under the resouces folder, which is the classpath resource
//@ContextConfiguration(locations={"classpath:root-context.xml","classpath:spring.xml","classpath:spring-hibernate.xml"})
//Method 4: use the annotation @ContextConfiguration, and use File to locate the XMl files under webapp/web-inf
//@ContextConfiguration(locations={"file:src/main/webapp/WEB-INF/spring/root-context.xml", "file:src/main/webapp/WEB-INF/spring/spring.xml", "file:src/main/webapp/WEB-INF/spring/spring-hibernate.xml"})
public class TestCourseDao {
@Autowired
ICourseDao courseDao;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
}
@Before
public void setUp() throws Exception {
// Method 2: use the @Before annotation and call XMl under the resouces folder by ClassPathXmlApplicationContext, then initial one instance by get Bean
// ApplicationContext applicationContext = new ClassPathXmlApplicationContext(new String[] {"classpath:root-context.xml", "classpath:spring.xml", "classpath:spring-hibernate.xml" });
// Method 3: use the @Before annotation and call XMl under the web-inf folder by FileSystemXmlApplicationContext, then initial one instance by get Bean
// ApplicationContext applicationContext = new FileSystemXmlApplicationContext("classpath:src/main/resources/*.xml");
// courseDao = (ICourseDao) applicationContext.getBean("courseDao");
}
@After
public void tearDown() throws Exception {
}
@Test
public void testGetCourseList() {
assertNotNull(courseDao);
}
}
阅读全文
0 0
- Junit 调用Spring XML资源文件的方式
- 使用spring方式进行junit,报错xml文件不存在
- spring加载xml文件的方式
- spring-mvc.xml文件的配置方式
- wpf 调用自己编写的。xml后缀文件的资源
- Spring配置资源文件的两种方式
- spring mvc 访问静态资源文件的三种方式
- spring 配置国际化资源文件的两种方式
- spring 配置国际化资源文件的两种方式(转)
- Spring中加载外部资源文件的几种方式
- Junit 单元测试 Spring 读取WEB-INF下 xml 文件
- Spring中加载ApplicationContext.xml文件的方式
- Spring中加载ApplicationContext.xml文件的方式
- Spring中加载ApplicationContext.xml文件的方式【转】
- Spring中加载ApplicationContext.xml文件的方式
- Spring中加载ApplicationContext.xml文件的方式
- Spring中加载ApplicationContext.xml文件的方式
- Spring中加载ApplicationContext.xml文件的方式
- Linux 守护进程
- orical空间数据类型GEOMETRY使用干货
- Varnish 进阶配置与实例
- IDEA破解 2017 IDEA license server 激活(可用)
- fig14_14.cpp
- Junit 调用Spring XML资源文件的方式
- Ubuntu下Mysql的主从配置(一)
- Spring框架第一篇HelloWorld
- MSQL之INSTR函数简单使用之代替LIKE执行模糊查询
- linux学习 python编程初识
- C++多线程互斥计数
- 耦合技术的应用
- 工作学习笔记之salt&request.getRemoteAdder()
- 转:私有云架构图