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

 susan0912010311fool 发布于 2022-10-27 01:20
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已经配置了扫描接口

    
        
        
    

该如何解决?

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

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

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

    2022-10-27 01:43 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有