У меня есть исходный класс, который явно нарушает интеграционный тест. Код приведен ниже.
@Configuration
@Import( EmailageConfiguration.class )
public class EmailageServiceConfiguration {
private static final String EMAILAGE_ACCOUNT_ID_CONFIG_KEY = "emailage.key";
private static final String EMAILAGE_API_KEY_CONFIG_KEY = "emailage.secret";
private final EmailageConfigHolder holder;
public EmailageServiceConfiguration( final EmailageConfigHolder holder ) {
this.holder = holder;
}
@Bean
public EmailageConfigHolder emailageConfigHolder( Environment env ) {
// final EmailageConfigHolder holder = new EmailageConfigHolder();
holder.setApiKey( env.getRequiredProperty( EMAILAGE_API_KEY_CONFIG_KEY ) );
holder.setAccountId( env.getRequiredProperty( EMAILAGE_ACCOUNT_ID_CONFIG_KEY ) );
return holder;
}
}
ИТ-тест предоставляется,
public class EmailageServiceIT {
private static final String EMAILAGE_RESPONSE_FILE = "emailage-response.json";
private final static String EMAILAGE_ENDPOINT = "/emailage";
private EmailageService service;
@Rule
public WireMockRule wireMockRule = new WireMockRule( wireMockConfig().dynamicPort() );
@Before
@SuppressWarnings( "resource" )
public void setup() {
int port = wireMockRule.port();
System.setProperty( "emailage.uri", "http://localhost:" + port + EMAILAGE_ENDPOINT );
System.setProperty( "emailage.key", "123" );
System.setProperty( "emailage.secret", "123" );
System.setProperty( "emailage.connection_timeout", "10000" );
System.setProperty( "emailage.read_timeout", "10000" );
System.setProperty( "kafka.bootstrap_servers", "localhost" );
System.setProperty( "kafka.topic", "ella-test-topic" );
ApplicationContext context = new AnnotationConfigApplicationContext( EmailageServiceConfiguration.class );
service = context.getBean( EmailageService.class );
}
// .........................
}
Когда я запускаю команду maven, я получаю стек ошибок,
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'emailageServiceConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'emailageServiceConfiguration': Requested bean is currently in creation: Is there an unresolvable circular reference?
at com.ratepay.ella.service.EmailageServiceIT.setup(EmailageServiceIT.java:64)
Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'emailageServiceConfiguration': Requested bean is currently in creation: Is there an unresolvable circular reference?
at com.ratepay.ella.service.EmailageServiceIT.setup(EmailageServiceIT.java:64)
Итак, ИТ-тест в основном ломается в LOC,
ApplicationContext context = new AnnotationConfigApplicationContext( EmailageServiceConfiguration.class );
Я также добавляю класс EmailageConfigHolder
для вопроса,
@Getter
@Setter
public class EmailageConfigHolder {
private String apiKey;
private String accountId;
}
Как мне исправить это?