@SpringBootTest()
@RunWith(SpringRunner.class)
public class ProductMapperTest {
@Autowired
ProductMapper productMapper;
3:为了给mapper接口 自动根据一个添加@Mapper注解的接口生成一个实现类
怎么注入都是失败,ProductMapper 使用@Mapper 注解,这个不能注入到spring 容器中(其中原因还是不了解)。@Autowired 注入不进去的。
@Repository
@Mapper
public interface ProductMapper {
这下能注入容器中了。
本文探讨了在SpringBoot项目中,如何正确地使用@Mapper注解将MyBatis的Mapper接口注入到Spring容器中。通过添加@Repository注解,成功解决了@Autowired无法注入的问题。
7161

被折叠的 条评论
为什么被折叠?



