搜索

首页  >  问答  >  正文

java - junit进行测试的时候无法注入接口?

package org.dao;

import org.entity.Seckill;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

import static org.junit.Assert.*;

/**
 * Created by Administrator on 16.11.11.
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"/spring/spring-dao.xml"})
public class SeckillDAOTest {



    @Resource
    private SeckillDAO seckillDAO;


    @Test
    public void queryById() throws Exception {
        Seckill seckill = seckillDAO.queryById(1000L);
        System.out.println(seckill.getName());
    }

    @Test
    public void reduceNumber() throws Exception {

    }

    @Test
    public void queryAll() throws Exception {

    }



}

上面是测试类, 在 private SeckillDAO seckillDAO处警告could not autowire. No beans of 'SeckillDAO' type found。然而spring-dao.xml已经配置了扫描接口


    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
        <property name="basePackage" value="org.dao"/>
    </bean>

该如何解决?

怪我咯怪我咯2769 天前906

全部回复(1)我来回复

  • 天蓬老师

    天蓬老师2017-04-18 10:21:18

    确定加载到配置文件了吗?如果配置文件是放在resources下的话试试:

    @ContextConfiguration(locations = {"classpath:spring/spring-dao.xml"})

    或者其它你自己的配置文件的路径。

    回复
    0
  • 取消回复