java - junit进行测试的时候无法注入接口?
怪我咯
怪我咯 2017-04-18 10:19:18
0
1
916
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>

该如何解决?

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(1)
Peter_Zhu

Are you sure it has been loaded into the configuration file? If the configuration file is placed under resources, try:

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

Or the path to your own configuration file.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template