package de.otto.edison.vault;

import com.ning.http.client.AsyncHttpClient;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

@Component
@ConditionalOnProperty(prefix = "edison.vault", name = "enableconfigurer", matchIfMissing = true)
public class VaultPropertyPlaceholderConfigurer extends PropertySourcesPlaceholderConfigurer {

    protected Environment environment;

    @Autowired
    private AsyncHttpClient asyncHttpClient;

    @Override
    public void postProcessBeanFactory(final ConfigurableListableBeanFactory beanFactory) throws BeansException {
        ConfigProperties configProperties = new ConfigProperties(environment);
        VaultReader vaultReader = new VaultReader(configProperties, VaultClient.vaultClient(configProperties, new VaultToken(configProperties, asyncHttpClient)));
        if (vaultReader.vaultEnabled()) {
            setProperties(vaultReader.fetchPropertiesFromVault());
        }
        super.postProcessBeanFactory(beanFactory);
    }

    @Override
    public void setEnvironment(final Environment environment) {
        this.environment = environment;
        super.setEnvironment(environment);
    }


}

@@ -770,69 +770,8 @@
 t;%0A%0A
-    @Autowired%0A    private AsyncHttpClient asyncHttpClient;%0A%0A
     
@@ -1116,17 +1116,21 @@
 erties, 
-a
+new A
 syncHttp
@@ -1135,16 +1135,18 @@
 tpClient
+()
 )));%0A   

remove autowired, because it is not available at this stage