mybatis动态代理mapper(interface),然后用@Res..注入一直报错,然后无奈用了配置文件,
在service层用get/set方法来做,发现这个MAPPER还是空的!!
@Service("testService")
public class TestServiceImpl implements TestService{
private TestMapper testMapper;
public TestMapper getTestMapper() {
return testMapper;
}
public void setTestMapper(TestMapper testMapper) {
this.testMapper = testMapper;
}
@Transactional
@Override
public Object tset1(){
TestMapper mapper = ApplicationContextFactory.getBean("testMapper", TestMapper.class);
mapper.insertOne();
throw new RuntimeException("test");
}
}
如上,但是ApplicationContextFactory.getBean又可以取到并且操作,扫描包应是没问题的,不然应该会报错吧