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

The following examples show how to use org.springframework.boot.autoconfigure.condition.ConditionalOnBean. 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 check out the related API usage on the sidebar.
Example #1
Source File: MailAutoConfiguration.java    From cola-cloud with MIT License 7 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 #2
Source File: EnableApiDiscoveryConfig.java    From api-layer with Eclipse Public License 2.0 6 votes vote down vote up
@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 File: KafkaAutoConfiguration.java    From extension-kafka with 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 #4
Source File: DefaultEmbeddedWebappsAutoConfiguration.java    From super-cloudops with Apache License 2.0 5 votes vote down vote up
@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 #5
Source File: ErrorsAutoConfiguration.java    From errors-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #6
Source File: RSocketAutoConfiguration.java    From alibaba-rsocket-broker with Apache License 2.0 5 votes vote down vote up
@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 #7
Source File: EntityLinkingServiceAutoConfiguration.java    From inception with Apache License 2.0 5 votes vote down vote up
@ConditionalOnBean(RecommendationService.class)
@Bean
@Autowired
public NamedEntityLinkerFactory namedEntityLinkerFactory(KnowledgeBaseService aKbService,
        ConceptLinkingService aClService, FeatureSupportRegistry aFsRegistry)
{
    return new NamedEntityLinkerFactory(aKbService, aClService, aFsRegistry);
}
 
Example #8
Source File: ReactiveLightSecurityConfiguration.java    From light-security with 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 #9
Source File: XsuaaTokenFlowAutoConfiguration.java    From cloud-security-xsuaa-integration with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #10
Source File: XsrfAutoConfiguration.java    From super-cloudops with 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 #11
Source File: ErrorsAutoConfiguration.java    From errors-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #12
Source File: LightSecurityConfiguration.java    From light-security with 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 #13
Source File: BrokerApplication.java    From WeEvent with 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 #14
Source File: EnableApiDiscoveryConfig.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
@ConditionalOnBean(EurekaClientProvider.class)
@Bean
public ApiMediationClient apiMediationClient(EurekaClientProvider eurekaClientProvider) {
    if (eurekaClientProvider == null) {
        return new ApiMediationClientImpl();
    }
    return new ApiMediationClientImpl(eurekaClientProvider);
}
 
Example #15
Source File: BrokerApplication.java    From WeEvent with 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 #16
Source File: RaptorServiceAutoConfiguration.java    From raptor with 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 #17
Source File: SqlSessionHotspotAutoConfiguration.java    From super-cloudops with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnJdwpDebug(enableProperty = KEY_PREFIX + ".enable")
@ConfigurationProperties(prefix = KEY_PREFIX)
@ConditionalOnBean(SqlSessionFactoryBean.class)
public HotspotLoadProperties hotspotLoaderProperties() {
	return new HotspotLoadProperties();
}
 
Example #18
Source File: J2CacheSpringCacheAutoConfiguration.java    From J2Cache with Apache License 2.0 5 votes vote down vote up
@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 #19
Source File: J2CacheSpringCacheAutoConfiguration.java    From J2Cache with Apache License 2.0 5 votes vote down vote up
@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 #20
Source File: J2CacheSpringRedisAutoConfiguration.java    From J2Cache with Apache License 2.0 5 votes vote down vote up
@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
Source File: SecureConfiguration.java    From magic-starter with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 #22
Source File: J2CacheSpringCacheAutoConfiguration.java    From spring-boot-tutorial with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
@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 #23
Source File: ChronusAutoConfiguration.java    From chronus with 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 #24
Source File: CorsAutoConfiguration.java    From super-cloudops with 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 #25
Source File: OpenIdAuthenticationConfiguration.java    From cola with 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 #26
Source File: DubboAutoConfiguration.java    From dubbo-spring-boot-project with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #27
Source File: SmsOAuth2Configuration.java    From cola with 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 #28
Source File: TracingConfig.java    From x7 with 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 #29
Source File: CenterConfig.java    From earth-frost with Apache License 2.0 4 votes vote down vote up
@Bean
@ConditionalOnBean(Notifier.class)
public CompositeNotifier compositeNotifier(Map<String, Notifier> notifiers) {
  return new CompositeNotifier(notifiers.values());
}
 
Example #30
Source File: OMSAutoConfiguration.java    From joyqueue with Apache License 2.0 4 votes vote down vote up
@Bean
@ConditionalOnBean(AccessPointContainer.class)
@ConditionalOnProperty(prefix = OMSSpringBootConsts.PREFIX + ".consumer", name = "enable", matchIfMissing = true, havingValue = "true")
public ConsumerRegistrar createConsumerRegistrar(AccessPointContainer accessPointContainer) {
    return new ConsumerRegistrar(accessPointContainer);
}