两种方法: 1、在application.properties的配置文件中新增spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true; 2、在测试的方法上添加@Transactional注解。