zoukankan      html  css  js  c++  java
  • 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)咨询.

  • 相关阅读:
    jquery1.9之学习笔记
    ERROR: Removing 'hello': Device or resource busy
    windows虚拟机性能调整
    kvm虚拟机控制台登录配置
    KVM虚拟机的管理
    window kvm 虚拟机的创建
    kvm虚拟化环境的搭建
    C实现哈希表
    哲学家就餐问题 C语言实现
    Linux面试题
  • 原文地址:https://www.cnblogs.com/JAYIT/p/14500779.html
Copyright © 2011-2022 走看看