m0_56657421
2021-06-09 18:46
采纳率: 100%
浏览 129
已结题

springMVC项目,遇到@Autowired注入为null,空指针错误

看网上视频跟着学的SpringMVC,不知道是哪里出错了?

applicationContext.xml文件扫描:

<context:component-scan base-package="com.atguigu">
    <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>

Mapper测试类,两个注入都是null:

@ExtendWith(SpringExtension.class)//spring junit5
@ContextConfiguration(locations = {"classpath:applicationContext.xml"})
public class MapperTest {

    @Autowired
    DepartmentMapper departmentMapper;

    @Autowired
    EmployeeMapper employeeMapper;

文件结构:

DepartmentMapper和EmployeeMapper接口上添加注解或者不添加注解都一样的结果,请问是哪里出错了?

错误信息:

null

java.lang.NullPointerException: Cannot invoke "com.atguigu.crud.dao.EmployeeMapper.insertSelective(com.atguigu.crud.bean.Employee)" because "this.employeeMapper" is null

    at com.atguigu.crud.test.MapperTest.testCRUD(MapperTest.java:45)

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

相关推荐 更多相似问题