use of org.springframework.context.annotation.Conditional in project zipkin by openzipkin.
the class ZipkinElasticsearchStorageConfiguration method dynamicCredentialsScheduledExecutorService.
@Bean(destroyMethod = "shutdown")
@Qualifier(QUALIFIER)
@Conditional(DynamicRefreshRequired.class)
ScheduledExecutorService dynamicCredentialsScheduledExecutorService(@Value("${" + CREDENTIALS_FILE + "}") String credentialsFile, @Value("${" + CREDENTIALS_REFRESH_INTERVAL + "}") Integer credentialsRefreshInterval, @Qualifier(QUALIFIER) BasicCredentials basicCredentials) throws IOException {
ScheduledExecutorService ses = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("zipkin-load-es-credentials"));
DynamicCredentialsFileLoader credentialsFileLoader = new DynamicCredentialsFileLoader(basicCredentials, credentialsFile);
credentialsFileLoader.updateCredentialsFromProperties();
ScheduledFuture<?> future = ses.scheduleAtFixedRate(credentialsFileLoader, 0, credentialsRefreshInterval, TimeUnit.SECONDS);
if (future.isDone())
throw new RuntimeException("credential refresh thread didn't start");
return ses;
}
use of org.springframework.context.annotation.Conditional in project vboard by voyages-sncf-technologies.
the class WebSecurityConfig method adapterDeploymentContext.
// Also injected in `KeycloakPreAuthActionsFilter` as the `deploymentContext` property through the `initFilterBean` method.
// !BEWARE! if this `deploymentContext` property ends up null, it will lead to a NullPointerException in `org.keycloak.adapters.PreAuthActionsHandler.preflightCors:107`
@Bean
@Conditional(KeycloakEnabledInEnv.class)
public static AdapterDeploymentContext adapterDeploymentContext() throws Exception {
AdapterDeploymentContextFactoryBean factoryBean = new AdapterDeploymentContextFactoryBean(new KeycloakSpringBootConfigResolver());
// creates the AdapterDeploymentContext
factoryBean.afterPropertiesSet();
return factoryBean.getObject();
}
use of org.springframework.context.annotation.Conditional in project flow by vaadin.
the class SpringBootAutoConfiguration method dispatcherServletRegistration.
/**
* Creates a {@link ServletRegistrationBean} instance for a dispatcher
* servlet in case Vaadin servlet is mapped to the root.
* <p>
* This is needed for correct servlet path (and path info) values available
* in Vaadin servlet because it works via forwarding controller which is not
* properly mapped without this registration.
*
* @return a custom ServletRegistrationBean instance for dispatcher servlet
*/
@Bean
@Conditional(RootMappedCondition.class)
public ServletRegistrationBean<DispatcherServlet> dispatcherServletRegistration() {
DispatcherServlet servlet = context.getBean(DispatcherServlet.class);
ServletRegistrationBean<DispatcherServlet> registration = new ServletRegistrationBean<>(servlet, "/*");
registration.setName("dispatcher");
return registration;
}
use of org.springframework.context.annotation.Conditional in project java-chassis by ServiceComb.
the class ConfigurationSpringInitializer method addMicroserviceYAMLToSpring.
/**
* make springboot have a change to add microservice.yaml source earlier<br>
* to affect {@link Conditional}
* @param environment environment
*/
private static void addMicroserviceYAMLToSpring(Environment environment) {
if (!(environment instanceof ConfigurableEnvironment)) {
return;
}
MutablePropertySources propertySources = ((ConfigurableEnvironment) environment).getPropertySources();
if (propertySources.contains(MICROSERVICE_PROPERTY_SOURCE_NAME)) {
return;
}
propertySources.addLast(new EnumerablePropertySource<MicroserviceConfigLoader>(MICROSERVICE_PROPERTY_SOURCE_NAME) {
private final Map<String, Object> values = new HashMap<>();
private final String[] propertyNames;
{
MicroserviceConfigLoader loader = new MicroserviceConfigLoader();
loader.loadAndSort();
loader.getConfigModels().forEach(configModel -> values.putAll(YAMLUtil.retrieveItems("", configModel.getConfig())));
propertyNames = values.keySet().toArray(new String[values.size()]);
}
@Override
public String[] getPropertyNames() {
return propertyNames;
}
@SuppressWarnings("unchecked")
@Override
public Object getProperty(String name) {
Object value = this.values.get(name);
// spring will not resolve nested placeholder of list, so try to fix the problem
if (value instanceof List) {
value = ((List<Object>) value).stream().filter(item -> item instanceof String).map(item -> environment.resolvePlaceholders((String) item)).collect(Collectors.toList());
}
return value;
}
});
}
Aggregations