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

该如何解决?

怪我咯
怪我咯

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

Antworte allen(1)
Peter_Zhu

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

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

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

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage