我有一个在 Spring Boot 2.3.8 中运行良好的应用程序,但@RestClientTest
s 在 2.4.2 中失败,因为无法实例化测试对象,因为没有 bean @ConfigurationProperties
(由@TestConfiguration
.
我如何更改我的代码以使其适用于 2.4.x?
代码是:
@Configuration
@ConfigurationProperties(prefix = "tyntec.routetest.dsidr")
@Data
@Validated
public class DynamicSenderIdReplacementClientConfiguration {
@NotBlank
private String baseUrl;
@NotBlank
private String dsidrPath;
}
@Component
@RequiredArgsConstructor
public class DynamicSenderIdReplacementClient {
private final DynamicSenderIdReplacementClientConfiguration configuration;
}
@ExtendWith(SpringExtension.class)
@RestClientTest(DynamicSenderIdReplacementClient.class)
@AutoConfigureWebClient(registerRestTemplate = true)
class DynamicSenderIdReplacementClientWebTest {
@Autowired
private DynamicSenderIdReplacementClient cut;
@TestConfiguration
static class testConfiguration {
@Bean
@Primary
public DynamicSenderIdReplacementClientConfiguration provideConfig() {
return new DynamicSenderIdReplacementClientConfiguration() {
{
setBaseUrl(BASE_URL);
setDsidrPath(DSIDR_PATH);
}
};
}
}
这在 2.3.8 中有效,但在 2.4.2 中失败
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.tyntec.routetesting.client.itest.clients.DynamicSenderIdReplacementClientConfiguration' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}