zoukankan      html  css  js  c++  java
  • 搭建spring3.2+junit4单元测试

    1.引入所需jar包,spring-3.2*.jar、junit4.x.jar等;

    2.配置sping-test.xml文件,并将文件放在源路径下:

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <beans xmlns="http://www.springframework.org/schema/beans"
     3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     4     xmlns:context="http://www.springframework.org/schema/context"
     5     xmlns:mvc="http://www.springframework.org/schema/mvc"
     6     xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
     7     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
     8     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
     9     <!-- zi dong sao mian qie zhi sao mian@Controller -->
    10     <context:component-scan base-package="com.eastcom_sw" use-default-filters="false">
    11         <context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
    12     </context:component-scan>
    13     <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
    14         <property name="dataSource">
    15             <ref local="dataSource"/>
    16         </property>
    17     </bean>
    18     <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    19         <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
    20         <property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:orcl"/>
    21         <property name="username" value="orcl" />
    22         <property name="password" value="orcl123" />
    23     </bean>
    24 </beans>

    3.编写单元测试类:

     1 @RunWith(SpringJUnit4ClassRunner.class)  //使用junit4进行测试  
     2 @ContextConfiguration(locations={"classpath*:spring-test.xml"})//加载spring文件
     3 @TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)//配置事务  
     4 public class MyWebTest{
     5     
     6     @Resource  
     7     private JdbcTemplate jdbcTemplate; //注入jdbctemplate类
     8  
     9     @Test
    10     public void test01(){
    11         List<Map<String, Object>> list = jdbcTemplate.queryForList("select * from scott.emp");
    12         
    13         System.out.println(list.size());
    14         
    15     }
    16 
    17
  • 相关阅读:
    js基础 ---- 为什么定时器时间不准确
    vue 3.0 ---- reactive函数
    vue 3.0 ---- ref函数
    vue 3.0 ---- setup函数
    vue 3.0 ---- 什么是vite
    Vue warn]: Error in event handler for "click": "TypeError: fns.apply is not a function"
    vueJs 自动清除文本框的 空格
    vue 报错解决 -------- DOMException: Failed to execute 'insertBefore' on 'Node' --------------------"NotFoundError: Failed to execute 'insertBefore' on 'Node': The node before
    vue 中 uuid 的使用以及作用
    赞不绝口钉钉自动点赞器
  • 原文地址:https://www.cnblogs.com/davidxu/p/5823156.html
Copyright © 2011-2022 走看看