Error creating bean with name
程序员文章站
2022-07-14 21:13:23
...
今天执行单测时候遇到下面报错
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);
}
}
推荐阅读
-
Error creating bean with name 'entityManagerFactory' defined in class path resource解决方案
-
sqlserver the name is not a valid identifier error in function
-
Error creating bean with name ‘eduChapterController‘: Unsatisfied dependency expressed through field
-
UnsatisfiedDependencyException: Error creating bean with name ‘xxxx‘:
-
springMVC常见错误-解决org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.spring
-
Error creating liferay plugin projct.Please see eclipse error log for more details 问题解决
-
Annotation-specified bean name 'xxxController' for bean class conflicts with existing
-
Error creating bean with name
-
Error creating bean with name 'eurekaAutoServiceRegistration'
-
Error creating bean with name报错