【发布时间】:2021-03-15 23:07:34
【问题描述】:
我有一个 SpringBoot 应用程序。使用此服务:
@Slf4j
@Service
public class AddressService {
private final RegionRepository regionRepository;
private final CommuneRepository communeRepository;
private final RestTemplate restTemplate;
public AddressService(RegionRepository regionRepository,
CommuneRepository communeRepository,
RestTemplate restTemplate) {
this.regionRepository = regionRepository;
this.communeRepository = communeRepository;
this.restTemplate = restTemplate;
}
public GeolocationAddress searchFromAddress(String address) {
// (..)
}
}
我已经创建了这个测试:
@ExtendWith(SpringExtension.class)
@SpringBootTest
class AddressServiceTest {
@Autowired
AddressService addressService;
@Test
void searchFromAddress() {
System.out.println
(addressService.searchFromAddress("Plaza los Cubos)"));
}
}
但是当我运行测试时出现这个错误:
***************************
APPLICATION FAILED TO START
***************************
说明:
com.bonansa.service.AddressService 中构造函数的参数 2 需要一个无法找到的 'org.springframework.web.client.RestTemplate' 类型的 bean。
动作:
考虑在你的配置中定义一个 'org.springframework.web.client.RestTemplate' 类型的 bean。
【问题讨论】:
-
请出示您的 POM/
build.gradle。您似乎没有为您自动配置RestTemplate的依赖项。
标签: java spring spring-boot spring-mvc junit