看网上视频跟着学的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)
原因找到了,spring-test包和junit包的版本没有对应造成的
propertie文件的内容贴一下,另外启动类上加MapperScan注解了吗
你正常的代码是否正常,先排除下 是测试代码配置的问题