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>
该如何解决?
确定加载到配置文件了吗?如果配置文件是放在resources下的话试试:
或者其它你自己的配置文件的路径。