使用gradle(3.4.1)和integrationTest配置,使用Spring Boot的ConfigurationProperties(1.5.1.RELEASE)進行的測試無法初始化,即使應用程序正確初始化( ./gradlew bootRun)。使用ConfigurationProperties註解的類與以下內容類似Spring Boot ConfigurationProperties無法初始化以進行集成測試
@Component
@ConfigurationProperties(prefix = "foo")
@Validated
public class AppConfiguration {
@NonNull
private URL serviceUrl;
...
配置文件確實有getter和setter。所產生的誤差是類似於
java.lang.IllegalStateException: Failed to load ApplicationContext
....
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'AppConfiguration': Could not bind properties to AppConfiguration
....
Caused by: org.springframework.validation.BindException: org.springframework.boot.bind.RelaxedDataBinder$RelaxedBeanPropertyBindingResult
Field error in object 'foo' on field 'serviceUrl': rejected value [null]; codes ...
的配置類集成測試的被註釋如下如下
@Configuration
@ComponentScan(...)
@EnableConfigurationProperties
@EnableIntegration
public static class ContextConfiguration {}