SpringbootTest注入失败
正确方法:
/**
* *@author:sawsh
* *@date:2021/3/8
* *@Description:
**/
import com.sawsh.StartApplication;
import com.sawsh.entity.User;
import com.sawsh.mapper.UserDao;
import com.sawsh.service.UserService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import java.util.List;
/**
* *@author:sawsh
* *@date:2021/3/5
* *@Description:
**/
//@SpringBootTest
@RunWith(SpringRunner.class)
@SpringBootTest(classes = StartApplication.class)
public class UserTest {
@Autowired
private UserDao userDao;
@Autowired
private UserService userService;
@Test
public void toTest(){
List<User> userLogins = userDao.queryAll();
userLogins.forEach(e-> System.out.println(e));
}
}
StartApplication是启动类
作者: lost blog
出处: http://www.cnblogs.com/JAYIT/
关于作者:专注服务器端开发
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接 如有问题, 可邮件(sawyershaw@qq.com)咨询.

浙公网安备 33010602011771号