org.zodiac.autoconfigure.hypermedia.HypermediaAutoConfiguration Maven / Gradle / Ivy
package org.zodiac.autoconfigure.hypermedia;
import java.util.Collections;
import java.util.List;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.zodiac.core.bootstrap.hypermedia.AppRemoteResource;
import org.zodiac.core.bootstrap.hypermedia.AppRemoteResourceRefresher;
/**
* Registers a default {@link AppRemoteResourceRefresher} if at least one {@link AppRemoteResource} is declared in the
* system. Applies verification timings defined in the application properties.
*
*/
@SpringBootConfiguration
@ConditionalOnBean(type = "org.zodiac.core.bootstrap.hypermedia.RemoteResource")
@EnableConfigurationProperties(value = {HypermediaProperties.class})
public class HypermediaAutoConfiguration {
//@Autowired(required = false)
private List discoveredResources = Collections.emptyList();
//@Autowired
private HypermediaProperties properties;
public HypermediaAutoConfiguration(ObjectProvider> discoveredResourcesProvider, HypermediaProperties properties) {
this.discoveredResources = discoveredResourcesProvider.getIfAvailable();
this.properties = properties;
}
@Bean
@ConditionalOnMissingBean
public AppRemoteResourceRefresher discoveredResourceRefresher() {
return new AppRemoteResourceRefresher(this.discoveredResources, this.properties.getRefresh().getFixedDelay(),
this.properties.getRefresh().getInitialDelay());
}
}