Java Code Examples for org.springframework.boot.autoconfigure.condition.ConditionalOnBean

The following examples show how to use org.springframework.boot.autoconfigure.condition.ConditionalOnBean. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: extension-kafka   Source File: KafkaAutoConfiguration.java    License: Apache License 2.0 6 votes vote down vote up
@Bean
@ConditionalOnMissingBean
@ConditionalOnBean({ConsumerFactory.class, KafkaMessageConverter.class, Fetcher.class})
@ConditionalOnProperty(value = "axon.kafka.consumer.event-processor-mode", havingValue = "TRACKING")
public StreamableKafkaMessageSource<String, byte[]> streamableKafkaMessageSource(
        ConsumerFactory<String, byte[]> kafkaConsumerFactory,
        Fetcher<String, byte[], KafkaEventMessage> kafkaFetcher,
        KafkaMessageConverter<String, byte[]> kafkaMessageConverter
) {
    return StreamableKafkaMessageSource.<String, byte[]>builder()
            .topics(Collections.singletonList(properties.getDefaultTopic()))
            .consumerFactory(kafkaConsumerFactory)
            .fetcher(kafkaFetcher)
            .messageConverter(kafkaMessageConverter)
            .bufferFactory(() -> new SortedKafkaMessageBuffer<>(properties.getFetcher().getBufferSize()))
            .build();
}
 
Example 2
@ConditionalOnBean(name = "EurekaClientProvider.class, EurekaClientConfigProvider.class")
@Bean
public ApiMediationClient apiMediationClient(EurekaClientProvider eurekaClientProvider, EurekaClientConfigProvider eurekaClientConfigProvider) {
    if (eurekaClientProvider != null) {
        if (eurekaClientConfigProvider != null) {
            return new ApiMediationClientImpl(eurekaClientProvider, eurekaClientConfigProvider);
        } else {
            return new ApiMediationClientImpl(eurekaClientProvider);
        }
    } else {
        if (eurekaClientConfigProvider != null) {
            return new ApiMediationClientImpl(new DiscoveryClientProvider(), eurekaClientConfigProvider);
        } else {
            return new ApiMediationClientImpl();
        }
    }
}
 
Example 3
Source Project: cola-cloud   Source File: MailAutoConfiguration.java    License: MIT License 6 votes vote down vote up
@Bean
@ConditionalOnBean(JavaMailSender.class)
public MailSender adiMailSender1(JavaMailSender sender, FreeMarkerConfigurer freeMarkerConfigurer) {
    if (mailProperties.getPreferIPv4Stack()) {
        System.setProperty("java.net.preferIPv4Stack", "true");
    }

    JavaMailSenderImpl js= (JavaMailSenderImpl) sender;
    Properties props = new Properties();
    props.put("mail.smtp.auth", true);
    props.put("mail.smtp.ssl.enable", true);
    props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
    props.put("mail.smtp.timeout", 25000);
    js.setJavaMailProperties(props);
    MailSender mailSender = new MailSender();
    mailSender.setJavaMailSender(js);
    mailSender.setFreeMarkerConfigurer(freeMarkerConfigurer);
    mailSender.setName(mailProperties.getName());
    mailSender.setFrom(mailProperties.getFrom());
    return mailSender;
}
 
Example 4
Source Project: x7   Source File: TracingConfig.java    License: Apache License 2.0 5 votes vote down vote up
@ConditionalOnMissingBean(BraveHttpRequestInterceptor.class)
@ConditionalOnBean(Brave.class)
@Bean
public BraveHttpRequestInterceptor requestInterceptor(Brave brave) {
    return new BraveHttpRequestInterceptor(brave.clientRequestInterceptor(),
            new DefaultSpanNameProvider());
}
 
Example 5
Source Project: light-security   Source File: LightSecurityConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnBean(SpecRegistry.class)
public List<Spec> specListFromSpecRegistry(SpecRegistry specRegistry) {
    List<Spec> specList = specRegistry.getSpecList();
    if (CollectionUtils.isEmpty(specList)) {
        throw new IllegalArgumentException("specList cannot be empty.");
    }
    return specList;
}
 
Example 6
@Bean
@ConditionalOnBean(SpecRegistry.class)
public List<Spec> specListFromSpecRegistry(SpecRegistry specRegistry) {
    List<Spec> specList = specRegistry.getSpecList();
    if (CollectionUtils.isEmpty(specList)) {
        throw new IllegalArgumentException("specList cannot be empty.");
    }
    return specList;
}
 
Example 7
/**
 * Registers an empty {@link ExceptionLogger} in the absence of a custom logger.
 *
 * @return A no-op exception logger.
 */
@Bean
@ConditionalOnMissingBean
@ConditionalOnBean(WebErrorHandlers.class)
public ExceptionLogger exceptionLogger() {
    return ExceptionLogger.NoOp.INSTANCE;
}
 
Example 8
@Bean
@ConditionalOnMissingBean
@ConditionalOnBean(type = "brave.Tracing")
public RSocketResponderHandlerFactory rsocketResponderHandlerFactoryWithZipkin(@Autowired LocalReactiveServiceCaller serviceCaller,
                                                                               @Autowired @Qualifier("reactiveCloudEventProcessor") TopicProcessor<CloudEventImpl> eventProcessor) {
    return (setupPayload, requester) -> Mono.fromCallable(() -> {
        RSocketResponderHandler responderHandler = new RSocketResponderHandler(serviceCaller, eventProcessor, requester, setupPayload);
        Tracing tracing = applicationContext.getBean(Tracing.class);
        responderHandler.setTracer(tracing.tracer());
        return responderHandler;
    });
}
 
Example 9
Source Project: WeEvent   Source File: BrokerApplication.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnBean(FiscoBcosDelegate.class)
public IProducer fiscoIProducer(FiscoBcosDelegate fiscoBcosDelegate) {
    FiscoBcosBroker4Producer fiscoBcosBroker4Producer = new FiscoBcosBroker4Producer(fiscoBcosDelegate);
    fiscoBcosBroker4Producer.startProducer();
    return fiscoBcosBroker4Producer;
}
 
Example 10
@ConditionalOnBean(EurekaClientProvider.class)
@Bean
public ApiMediationClient apiMediationClient(EurekaClientProvider eurekaClientProvider) {
    if (eurekaClientProvider == null) {
        return new ApiMediationClientImpl();
    }
    return new ApiMediationClientImpl(eurekaClientProvider);
}
 
Example 11
Source Project: WeEvent   Source File: BrokerApplication.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnBean(FabricDelegate.class)
public IProducer fabricIProducer(FabricDelegate fabricDelegate) {
    FabricBroker4Producer fabricBroker4Producer = new FabricBroker4Producer(fabricDelegate);
    fabricBroker4Producer.startProducer();
    return fabricBroker4Producer;
}
 
Example 12
@Bean
@ConditionalOnBean(SecureRuleRegistry.class)
public List<Rule> ruleListFromRegistry(SecureRuleRegistry secureRuleRegistry) {
	List<Rule> ruleList = secureRuleRegistry.getRuleList();
	if (CollectionUtils.isEmpty(ruleList)) {
		throw new IllegalArgumentException("规则列表不能为空");
	}
	return ruleList;
}
 
Example 13
Source Project: chronus   Source File: ChronusAutoConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnBean({ApplicationConfig.class, RegistryConfig.class})
public ChronusSdkProcessor chronusSdkFacade() {
    ChronusSdkProcessor chronusClientFacade = new AbstractSdkService(){};
    ServiceConfig<ChronusSdkProcessor> serviceConfig = new ServiceConfig<>();
    serviceConfig.setApplication(applicationConfig);
    serviceConfig.setRegistry(registryConfig);
    serviceConfig.setInterface(ChronusSdkProcessor.class);
    serviceConfig.setRef(chronusClientFacade);
    serviceConfig.setPath("/" + applicationConfig.getName() + "/" + ChronusSdkProcessor.class.getName());
    //serviceConfig.setGroup(applicationConfig.getName());
    serviceConfig.export();
    return chronusClientFacade;
}
 
Example 14
Source Project: cola   Source File: OpenIdAuthenticationConfiguration.java    License: MIT License 5 votes vote down vote up
@Bean
@ConditionalOnBean(OpenIdLoginConfigurer.class)
public OpenIdChannelSecurityConfigurer openIdChannelSecurityConfigurer(OpenIdLoginConfigurer openIdLoginConfigurer,
																	   OpenIdAuthenticationProvider openIdAuthenticationProvider,
																	   OpenIdProperties openIdProperties) {
	return new OpenIdChannelSecurityConfigurer(openIdLoginConfigurer,openIdAuthenticationProvider,openIdProperties);
}
 
Example 15
/**
 * Creates {@link ServiceAnnotationBeanPostProcessor} Bean
 *
 * @param propertyResolver {@link PropertyResolver} Bean
 * @return {@link ServiceAnnotationBeanPostProcessor}
 */
@ConditionalOnProperty(prefix = DUBBO_SCAN_PREFIX, name = BASE_PACKAGES_PROPERTY_NAME)
@ConditionalOnBean(name = BASE_PACKAGES_PROPERTY_RESOLVER_BEAN_NAME)
@Bean
public ServiceAnnotationBeanPostProcessor serviceAnnotationBeanPostProcessor(
        @Qualifier(BASE_PACKAGES_PROPERTY_RESOLVER_BEAN_NAME) PropertyResolver propertyResolver) {
    Set<String> packagesToScan = propertyResolver.getProperty(BASE_PACKAGES_PROPERTY_NAME, Set.class, emptySet());
    return new ServiceAnnotationBeanPostProcessor(packagesToScan);
}
 
Example 16
Source Project: cola   Source File: SmsOAuth2Configuration.java    License: MIT License 5 votes vote down vote up
@Bean
@ConditionalOnBean({AuthenticationManager.class, AuthorizationServerTokenServices.class, ClientDetailsService.class})
public SmsTokenGranter smsTokenGranter(AuthenticationManager authenticationManager,
									   AuthorizationServerTokenServices tokenServices,
									   ClientDetailsService clientDetailsService) {
	return new SmsTokenGranter(authenticationManager, tokenServices, clientDetailsService, new DefaultOAuth2RequestFactory(clientDetailsService));
}
 
Example 17
@Bean(BEAN_DEFAULT_EMBEDDED_WEBAPPS_ENDPOINT)
@ConditionalOnBean(name = BEAN_DEFAULT_EMBEDDED_WEBAPPS_PROPERTIES)
public GenericEmbeddedWebappsEndpoint defaultEmbeddedWebappsEndpoint(
		@Qualifier(BEAN_DEFAULT_EMBEDDED_WEBAPPS_PROPERTIES) GenericEmbeddedWebappsProperties config) {
	return new GenericEmbeddedWebappsEndpoint(config) {
	};
}
 
Example 18
Source Project: super-cloudops   Source File: CorsAutoConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnBean(CorsProperties.class)
public CorsSecurityFilter corsSecurityFilter(CorsProperties config, IamCorsProcessor corsProcessor) {
	UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
	// Merger transformation configuration
	config.getRules().forEach((key, rule) -> source.registerCorsConfiguration(key, rule.resolveIamCorsConfiguration()));
	CorsSecurityFilter filter = new CorsSecurityFilter(source);
	filter.setCorsProcessor(corsProcessor);
	return filter;
}
 
Example 19
@Bean
@ConditionalOnBean(CacheChannel.class)
public J2CacheCacheManger cacheManager(CacheChannel cacheChannel) {
    Collection<String> cacheNames = cacheProperties.getCacheNames();
    J2CacheCacheManger cacheCacheManger = new J2CacheCacheManger(cacheChannel);
    cacheCacheManger.setAllowNullValues(j2CacheProperties.isAllowNullValues());
    cacheCacheManger.setCacheNames(cacheNames);
    return cacheCacheManger;
}
 
Example 20
@Bean("j2CacheRedisTemplate")
@ConditionalOnBean(name = "j2CahceRedisConnectionFactory")
public RedisTemplate<String, Serializable> j2CacheRedisTemplate(
		@Qualifier("j2CahceRedisConnectionFactory") JedisConnectionFactory j2CahceRedisConnectionFactory) {
	RedisTemplate<String, Serializable> template = new RedisTemplate<String, Serializable>();
	template.setKeySerializer(new StringRedisSerializer());
	template.setHashKeySerializer(new StringRedisSerializer());
	template.setDefaultSerializer(new J2CacheSerializer());
	template.setConnectionFactory(j2CahceRedisConnectionFactory);
	return template;
}
 
Example 21
@Bean
@ConditionalOnBean(CacheChannel.class)
public J2CacheCacheManger cacheManager(CacheChannel cacheChannel) {
	List<String> cacheNames = cacheProperties.getCacheNames();
	J2CacheCacheManger cacheCacheManger = new J2CacheCacheManger(cacheChannel);
	cacheCacheManger.setAllowNullValues(j2CacheConfig.isAllowNullValues());
	cacheCacheManger.setCacheNames(cacheNames);
	return cacheCacheManger;
}
 
Example 22
@Bean
@ConditionalOnBean(CacheChannel.class)
public J2CacheCacheManger cacheManager(CacheChannel cacheChannel) {
	List<String> cacheNames = cacheProperties.getCacheNames();
	J2CacheCacheManger cacheCacheManger = new J2CacheCacheManger(cacheChannel);
	cacheCacheManger.setAllowNullValues(j2CacheConfig.isAllowNullValues());
	cacheCacheManger.setCacheNames(cacheNames);
	return cacheCacheManger;
}
 
Example 23
@Bean
@ConditionalOnJdwpDebug(enableProperty = KEY_PREFIX + ".enable")
@ConfigurationProperties(prefix = KEY_PREFIX)
@ConditionalOnBean(SqlSessionFactoryBean.class)
public HotspotLoadProperties hotspotLoaderProperties() {
	return new HotspotLoadProperties();
}
 
Example 24
Source Project: raptor   Source File: RaptorServiceAutoConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnBean(RequestMappingHandlerMapping.class)
public RaptorProtoFilesEndpoint createRaptorProtoFilesEndpoint(RequestMappingHandlerMapping requestMappingHandlerMapping) {
    RaptorProtoFilesEndpoint raptorProtoFilesEndpoint = new RaptorProtoFilesEndpoint(requestMappingHandlerMapping);
    raptorProtoFilesEndpoint.setClassLoader(classLoader);
    return raptorProtoFilesEndpoint;
}
 
Example 25
/**
 * Registers a {@link WebErrorHandler} to handle new Servlet exceptions defined in Spring Framework 5.1.
 * This handler would be registered iff we're using Spring Boot 2.1.0+.
 *
 * @return A web error handler to handle a few new servlet exceptions.
 */
@Bean
@ConditionalOnBean(WebErrorHandlers.class)
@ConditionalOnWebApplication(type = SERVLET)
@ConditionalOnClass(name = "org.springframework.web.bind.MissingRequestHeaderException")
public MissingRequestParametersWebErrorHandler missingRequestParametersWebErrorHandler() {
    return new MissingRequestParametersWebErrorHandler();
}
 
Example 26
Source Project: super-cloudops   Source File: XsrfAutoConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnBean(XsrfProperties.class)
public FilterRegistrationBean xsrfProtectionSecurityFilterBean(XsrfProtectionSecurityFilter filter) {
	// Register XSRF filter
	FilterRegistrationBean filterBean = new FilterRegistrationBean(filter);
	filterBean.setOrder(ORDER_XSRF_PRECEDENCE);
	// Cannot use '/*' or it will not be added to the container chain (only
	// '/**')
	filterBean.addUrlPatterns("/*");
	return filterBean;
}
 
Example 27
/**
 * Creates a new {@link XsuaaTokenFlows} bean that applications can auto-wire
 * into their controllers to perform a programmatic token flow exchange.
 *
 * @param xsuaaRestOperations
 *            - the {@link RestOperations} to use for the token flow exchange.
 * @param xsuaaServiceConfiguration
 *            - the {@link XsuaaServiceConfiguration} to configure the Xsuaa
 *            Base Url.
 * @return the {@link XsuaaTokenFlows} API.
 */
@Bean
@ConditionalOnBean({ XsuaaServiceConfiguration.class, RestOperations.class })
@ConditionalOnMissingBean
public XsuaaTokenFlows xsuaaTokenFlows(RestOperations xsuaaRestOperations,
		XsuaaServiceConfiguration xsuaaServiceConfiguration) {
	logger.debug("auto-configures XsuaaTokenFlows using restOperations of type: {}", xsuaaRestOperations);
	OAuth2ServiceEndpointsProvider endpointsProvider = new XsuaaDefaultEndpoints(
			xsuaaServiceConfiguration.getUaaUrl());
	ClientCredentials clientCredentials = new ClientCredentials(xsuaaServiceConfiguration.getClientId(),
			xsuaaServiceConfiguration.getClientSecret());
	OAuth2TokenService oAuth2TokenService = new XsuaaOAuth2TokenService(xsuaaRestOperations);
	return new XsuaaTokenFlows(oAuth2TokenService, endpointsProvider, clientCredentials);
}
 
Example 28
@ConditionalOnBean(RecommendationService.class)
@Bean
@Autowired
public NamedEntityLinkerFactory namedEntityLinkerFactory(KnowledgeBaseService aKbService,
        ConceptLinkingService aClService, FeatureSupportRegistry aFsRegistry)
{
    return new NamedEntityLinkerFactory(aKbService, aClService, aFsRegistry);
}
 
Example 29
@Bean(name = "redisUtil")
@ConditionalOnBean(RedisTemplate.class)
public RedisUtil redisUtils(RedisTemplate<String, Object> redisTemplate) {
	return new RedisUtil(redisTemplate);
}
 
Example 30
Source Project: super-cloudops   Source File: XsrfAutoConfiguration.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
@ConditionalOnBean(XsrfProperties.class)
public PrefixHandlerMapping xsrfProtectionEndpointPrefixHandlerMapping() {
	return super.newPrefixHandlerMapping(URI_XSRF_BASE, XsrfController.class);
}