junit继承spring配置信息


[html]  view plain  copy
  1. package com.baizhi.test;


    import java.io.FileInputStream;
    import java.util.Date;
    import java.util.List;
    import jxl.Cell;
    import jxl.Sheet;
    import jxl.Workbook;
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    import org.springframework.test.context.ContextConfiguration;
    import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;



    /**
     * @author Ain
     * @time 2017年2月12日下午4:39:28
     * @TODO
     */
    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration("classpath:/spring.xml")
    public class AdminTest {

    //定义成员变量
    @Autowired
    private MenuDao menuDao;
    @Autowired
    private MenuService menuService;


    @Test
    public void AdminTest1(){
    ApplicationContext ac = new ClassPathXmlApplicationContext("/spring.xml");
    AdminDao adminDao = ac.getBean(AdminDao.class);
    Admin admin = adminDao.checkLogin("admin");
    System.out.println(admin);
    }



    @Test
    public void importExcel() throws Exception{

    //获取excel文件输入流
    FileInputStream inputStream = new FileInputStream("C:\\Users\\Ain\\Desktop\\用户信息.xls");
    //通过输入流获取excel
    Workbook workbook = Workbook.getWorkbook(inputStream);
    //获取sheet页
    Sheet sheet = workbook.getSheet("用户信息");

    //获取sheet行数
    int rows = sheet.getRows();

    //获取sheet列数
    int columns = sheet.getColumns();

    //遍历获取数据 
    for (int i = 0; i < rows; i++) {

    for (int j = 0; j < columns; j++) {
    Cell cell = sheet.getCell(j,i); //第一个参数: 列索引  第二个参数: 行索引
    //获取单元格的内容
    String contents = cell.getContents();
    System.out.print(contents+ " ");
    }
    //打印完一行内容换行
    System.out.println();
    }

    workbook.close();
    }

    }

你可能感兴趣的:(环境配置)