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)
即可解决