TestRestTemplate注入时异常NoSuchBeanDefinitionException

来源:互联网 发布:渗透结晶防水涂料与js 编辑:程序博客网 时间:2024/06/05 19:00
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.ums.biz.user.service.UserServiceTest': Unsatisfied dependency expressed through field 'testRestTemplate'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.boot.test.web.client.TestRestTemplate' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

解决方式如下:
将头部的注解修改
@RunWith(SpringRunner.class)
@SpringBootTest
改为:
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
即可解决

阅读全文
0 0
原创粉丝点击