我有一个在springboot2.3.7中运行良好的应用程序,但是 @RestClientTest
s在2.4.1中失败,因为测试对象无法示例化,因为没有 @ConfigurationProperties
.
如何更改代码以使其适用于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.7中起作用,但在2.4.1中失败
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: {}
暂无答案!
目前还没有任何答案,快来回答吧!