Error creating bean with name

今天执行单测时候遇到下面报错
Error creating bean with name ‘com.liu.sptest.auth.AuthTest’: Injection of resource dependencies fai
在这里插入图片描述

package com.liu.sptest.auth;

import com.liu.sptest.OApiException;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import com.liu.sptest.service.DDService;
import com.liu.sptest.auth.AuthHelper;

import javax.annotation.Resource;

/**
 * @Author: beauty
 * @Date: 2020/6/17 5:18 下午
 */
@RunWith(SpringRunner.class)
@SpringBootTest
@Slf4j
public class AuthTest {
    @Resource
    private DDService ddService;
    //private AuthHelper authHelper;

    @Test
    public void testDDService() throws OApiException{
        //AuthHelper auth = new AuthHelper();
//        try {
//            ddService.te();
//        }catch (OApiException e)
//        System.out.println("ddddd");
        ddService.te();

    }
}

执行上面的单元测试报错
估计就是DDService有问题
感觉就是IOC的问题,当然IOC我也不很懂,反正就是service没装载进来吧
一通查IOC,也没搞明白
最后看其他的代码发现在DDService加这个注释就ok了
@Component这个注释意思是:
@component (把普通pojo实例化到spring容器中,相当于配置文件中的)
哎!一个注释就搞定了,害自己乱查半天!不过IOC还是要搞明白的,以后看看视频学习吧,看博客都不太清楚。

package com.liu.sptest.service;
import com.liu.sptest.OApiException;
import com.liu.sptest.auth.AuthHelper;
import org.springframework.stereotype.Component;


/**
 * @Author: beauty
 * @Date: 2020/6/17 4:45 下午
 */
@Component
public class DDService  {

    public void te() throws OApiException {
        String oo;
        oo = AuthHelper.getSsoToken();
        System.out.println("=========="+oo);
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值