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

The following examples show how to use org.springframework.boot.autoconfigure.condition.ConditionalOnClass. 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: ShardingTransactionProxyConfiguration.java    From opensharding-spi-impl with Apache License 2.0 6 votes vote down vote up
/**
 * Build hibernate transaction manager.
 *
 * @param transactionManagerCustomizers transaction manager customizers
 * @return jpa transaction manager
 */
@Bean
@ConditionalOnMissingBean(PlatformTransactionManager.class)
@ConditionalOnClass(value = LocalContainerEntityManagerFactoryBean.class, name = "javax.persistence.EntityManager")
public PlatformTransactionManager jpaTransactionManager(final ObjectProvider<TransactionManagerCustomizers> transactionManagerCustomizers) {
    JpaTransactionManager result = new JpaTransactionManager();
    if (null != transactionManagerCustomizers.getIfAvailable()) {
        transactionManagerCustomizers.getIfAvailable().customize(result);
    }
    return result;
}
 
Example #2
Source File: GrayTrackWebMvcConfiguration.java    From spring-cloud-gray with Apache License 2.0 6 votes vote down vote up
@Bean
@ConditionalOnBean(GrayTrackFilter.class)
@ConditionalOnClass(FilterRegistrationBean.class)
public FilterRegistrationBean grayTraceFilter(GrayTrackFilter filter) {
    GrayTrackProperties.Web webProperties = grayTrackProperties.getWeb();
    FilterRegistrationBean registration = new FilterRegistrationBean();
    //注入过滤器
    registration.setFilter(filter);
    //拦截规则
    for (String pattern : webProperties.getPathPatterns()) {
        registration.addUrlPatterns(pattern);
    }
    //过滤器名称
    registration.setName("GrayTrackFilter");
    //过滤器顺序
    registration.setOrder(FilterRegistrationBean.LOWEST_PRECEDENCE);
    return registration;
}
 
Example #3
Source File: LookoutAutoConfiguration.java    From sofa-lookout with Apache License 2.0 6 votes vote down vote up
/**
 * why use beanFactory to get DropWizardMetricsRegistry bean here?
 * because we do not want to import dropwizard dependencies indirectly!
 * let the application developer to decide whether or not to import.
 *
 * @return
 */
@Deprecated
@Bean
@ConditionalOnProperty(prefix = "com.alipay.sofa.lookout", name = "actuator-dropWizard-enabled", havingValue = "true", matchIfMissing = true)
@ConditionalOnClass(name = { "com.alipay.lookout.dropwizard.metrics.DropWizardMetricsRegistry",
        "com.codahale.metrics.MetricRegistry" })
public DropWizardMetricsRegistryFactory dropWizardMetricsRegistryFactory() {
    try {
        /*
         * In order to avoid [com.codahale.metrics.MetricRegistry] class not found.
         */
        com.codahale.metrics.MetricRegistry metricRegistry = beanFactory
            .getBean(com.codahale.metrics.MetricRegistry.class);
        if (metricRegistry == null) {
            logger
                .warn("spring boot actuator does not use dropwizard service,so lookout ignore dropwizard too!");
        } else {
            return new DropWizardMetricsRegistryFactory(metricRegistry);
        }
    } catch (NoClassDefFoundError e) {
        logger.debug("no dropwizard service found.");
    }
    return null;
}
 
Example #4
Source File: ReactiveStreamsServiceAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 6 votes vote down vote up
@Lazy
@Bean
@ConditionalOnMissingBean
@ConditionalOnClass(CamelContext.class)
public CamelReactiveStreamsService camelReactiveStreamsService(ApplicationContext ac) throws Exception {
    ReactiveStreamsEngineConfiguration engineConfiguration = new ReactiveStreamsEngineConfiguration();

    if (configuration.getReactiveStreamsEngineConfiguration() != null) {
        engineConfiguration = ac.getBean(configuration.getReactiveStreamsEngineConfiguration(), ReactiveStreamsEngineConfiguration.class);
    } else {
        engineConfiguration.setThreadPoolName(configuration.getThreadPoolName());
        if (configuration.getThreadPoolMinSize() != null) {
            engineConfiguration.setThreadPoolMinSize(configuration.getThreadPoolMinSize());
        }
        if (configuration.getThreadPoolMaxSize() != null) {
            engineConfiguration.setThreadPoolMinSize(configuration.getThreadPoolMaxSize());
        }
    }

    return ReactiveStreamsHelper.resolveReactiveStreamsService(context, configuration.getServiceType(), engineConfiguration);
}
 
Example #5
Source File: RocketMQAutoConfiguration.java    From rocketmq-spring-boot-starter with Apache License 2.0 6 votes vote down vote up
@Bean
@ConditionalOnClass(DefaultMQProducer.class)
@ConditionalOnMissingBean(DefaultMQProducer.class)
@ConditionalOnProperty(prefix = "spring.rocketmq", value = {"nameServer", "producer.group"})
public DefaultMQProducer mqProducer(RocketMQProperties rocketMQProperties) {

    RocketMQProperties.Producer producerConfig = rocketMQProperties.getProducer();
    String groupName = producerConfig.getGroup();
    Assert.hasText(groupName, "[spring.rocketmq.producer.group] must not be null");

    DefaultMQProducer producer = new DefaultMQProducer(producerConfig.getGroup());
    producer.setNamesrvAddr(rocketMQProperties.getNameServer());
    producer.setSendMsgTimeout(producerConfig.getSendMsgTimeout());
    producer.setRetryTimesWhenSendFailed(producerConfig.getRetryTimesWhenSendFailed());
    producer.setRetryTimesWhenSendAsyncFailed(producerConfig.getRetryTimesWhenSendAsyncFailed());
    producer.setMaxMessageSize(producerConfig.getMaxMessageSize());
    producer.setCompressMsgBodyOverHowmuch(producerConfig.getCompressMsgBodyOverHowmuch());
    producer.setRetryAnotherBrokerWhenNotStoreOK(producerConfig.isRetryAnotherBrokerWhenNotStoreOk());

    return producer;
}
 
Example #6
Source File: ChaosMonkeyConfiguration.java    From chaos-monkey-spring-boot with Apache License 2.0 5 votes vote down vote up
@Bean
@DependsOn("chaosMonkeyRequestScope")
@ConditionalOnClass(name = "org.springframework.data.repository.Repository")
// Creates aspects that match interfaces annotated with @Repository
public SpringRepositoryAspectJPA repositoryAspectJpa(
    ChaosMonkeyRequestScope chaosMonkeyRequestScope) {
  return new SpringRepositoryAspectJPA(chaosMonkeyRequestScope, publisher(), watcherProperties);
}
 
Example #7
Source File: SshShellAutoConfiguration.java    From ssh-shell-spring-boot with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
@ConditionalOnClass(name = "org.springframework.security.authentication.AuthenticationManager")
@ConditionalOnProperty(value = SSH_SHELL_PREFIX + ".authentication", havingValue = "security")
public SshShellAuthenticationProvider sshShellSecurityAuthenticationProvider(SshShellProperties properties) {
    return new SshShellSecurityAuthenticationProvider(context, properties.getAuthProviderBeanName());
}
 
Example #8
Source File: QuickFixJClientEndpointAutoConfiguration.java    From quickfixj-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnBean(name = { "clientInitiator", "clientSessionSettings" })
@ConditionalOnClass({ Initiator.class, SessionSettings.class })
@ConditionalOnMissingBean
@ConditionalOnEnabledEndpoint
public QuickFixJClientEndpoint quickfixjClientEndpoint(Initiator clientInitiator, SessionSettings clientSessionSettings) {
	return new QuickFixJClientEndpoint(clientInitiator, clientSessionSettings);
}
 
Example #9
Source File: ErrorsAutoConfiguration.java    From errors-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
/**
 * Registers a handler expert at handling all possible
 * {@link org.springframework.web.server.ResponseStatusException}s.
 *
 * @return A web error handler to handle a set of brand new exceptions defined in Spring 5.x.
 */
@Bean
@ConditionalOnBean(WebErrorHandlers.class)
@ConditionalOnClass(name = "org.springframework.web.server.ResponseStatusException")
public ResponseStatusWebErrorHandler responseStatusWebErrorHandler() {
    return new ResponseStatusWebErrorHandler();
}
 
Example #10
Source File: QuickFixJServerAutoConfiguration.java    From quickfixj-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnProperty(prefix = "quickfixj.server", name = "jmx-enabled", havingValue = "true")
@ConditionalOnClass(JmxExporter.class)
@ConditionalOnSingleCandidate(Acceptor.class)
@ConditionalOnMissingBean(name = "serverAcceptorMBean")
public ObjectName serverAcceptorMBean(Acceptor serverAcceptor) {
	try {
		JmxExporter exporter = new JmxExporter();
		exporter.setRegistrationBehavior(REGISTRATION_REPLACE_EXISTING);
		return exporter.register(serverAcceptor);
	} catch (Exception e) {
		throw new ConfigurationException(e.getMessage(), e);
	}
}
 
Example #11
Source File: SofaTracerFeignClientAutoConfiguration.java    From sofa-tracer with Apache License 2.0 5 votes vote down vote up
@Bean
@Scope("prototype")
@ConditionalOnClass(name = { "com.netflix.hystrix.HystrixCommand", "feign.hystrix.HystrixFeign" })
@ConditionalOnProperty(name = "feign.hystrix.enabled", havingValue = "true")
Feign.Builder feignHystrixBuilder() {
    return SofaTracerHystrixFeignBuilder.builder();
}
 
Example #12
Source File: ServletSecurityErrorsAutoConfiguration.java    From errors-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
/**
 * Registers a handler to handle to access denied exceptions.
 *
 * @return The registered access denied handler.
 */
@Bean
@ConditionalOnClass(name = "org.springframework.security.web.access.AccessDeniedHandler")
public AccessDeniedHandler accessDeniedHandler() {
    return (request, response, exception) -> {
        if (!response.isCommitted()) {
            request.setAttribute(ERROR_ATTRIBUTE, exception);
            response.sendError(HttpServletResponse.SC_FORBIDDEN);
        }
    };
}
 
Example #13
Source File: RedissonSpringAutoConfiguration.java    From redisson-spring-boot with Apache License 2.0 5 votes vote down vote up
/**
 * 声明 RedissonSpringCacheManager
 *
 * 由于 #{@link CacheAutoConfiguration} 的加载顺序在本类之前,并且其默认会注册一个 #{@link org.springframework.boot.autoconfigure.cache.SimpleCacheConfiguration},
 * 所以这里将 beanName 设置为 'cacheManager',目的是为了覆盖掉默认的 cacheManager(Spring 有一种机制来保证 bean 的优先级,详情请查看
 * #{@link DefaultListableBeanFactory#registerBeanDefinition(String, BeanDefinition)})
 *
 * 为什么不先加载本类呢?因为 CacheAutoConfiguration 中有一些功能是我们需要的,如果先加载本类,那么 RedissonSpringCacheManager注册成功后,
 * CacheAutoConfiguration 将不会加载,因为其加载条件是不存在 CacheManager
 *
 * @param redisson redisson 客户端
 * @return RedissonSpringCacheManager cacheManager
 */
@Bean
@ConditionalOnClass(CacheManager.class)
@ConditionalOnBean(CacheAspectSupport.class)
@ConditionalOnMissingBean(RedissonSpringCacheManager.class)
@ConditionalOnProperty(prefix = "spring.redisson.cache-manager", name = "enabled", havingValue = "true", matchIfMissing = true)
public RedissonSpringCacheManager cacheManager(RedissonClient redisson) {
    log.info("redisson cache-manager init...");
    RedissonCacheManagerProperties redissonCacheManagerProperties = redissonSpringProperties.getCacheManager();
    // 获取 ConfigMap
    // CacheConfig:
    //   ttl         过期时间,key 写入一定时间后删除,相当于 GuavaCache 的 expireAfterWrite
    //   maxIdleTime 最大空闲时间,key 一定时间内没有被访问后删除,相当于 GuavaCache 的 expireAfterAccess
    //   maxIdleTime 最大数量,达到一定数量后删除一部分 key,基于 LRU 算法
    Map<String, CacheConfig> config = redissonCacheManagerProperties.getConfigs();
    // 创建 CacheManager,ConfigMap 会转换为 Cache
    RedissonSpringCacheManager redissonSpringCacheManager = new RedissonSpringCacheManager(redisson, config);
    // RedissonSpringCacheManager 中的 dynamic 属性默认为 true,即获取不存在的 Cache 时,Redisson 创建一个永不过期的 Cache 以供使用
    // 个人认为这样不合理,会导致滥用缓存,所以 starter 中 dynamic 的默认值为 false,当获取不存在的 Cache 时会抛出异常
    // 当然,你也可以手动开启 dynamic 功能
    if (!redissonCacheManagerProperties.isDynamic()) {
        redissonSpringCacheManager.setCacheNames(redissonCacheManagerProperties.getConfigs().keySet());
    }
    if (redissonCacheManagerProperties.getCodec() != null) {
        redissonSpringCacheManager.setCodec(redissonCacheManagerProperties.getCodec().getInstance());
    }
    if (redissonCacheManagerProperties.getConfigLocation() != null && !redissonCacheManagerProperties.getConfigLocation().isEmpty()) {
        redissonSpringCacheManager.setConfigLocation(redissonCacheManagerProperties.getConfigLocation());
    }
    redissonSpringCacheManager.setAllowNullValues(redissonCacheManagerProperties.isAllowNullValues());
    // 用户自定义配置,拥有最高优先级
    redissonSpringCacheManagerCustomizers.forEach(customizer -> customizer.customize(redissonSpringCacheManager));
    return redissonSpringCacheManager;
}
 
Example #14
Source File: RxJavaMvcAutoConfiguration.java    From Java-9-Spring-Webflux with Apache License 2.0 5 votes vote down vote up
@Bean
@RxMVC
@ConditionalOnMissingBean
@ConditionalOnClass(Observable.class)
public ObservableReturnValueHandler observableReturnValueHandler() {
    return new ObservableReturnValueHandler();
}
 
Example #15
Source File: RxJavaMvcAutoConfiguration.java    From Java-9-Spring-Webflux with Apache License 2.0 5 votes vote down vote up
@Bean
@RxMVC
@ConditionalOnMissingBean
@ConditionalOnClass(Single.class)
public SingleReturnValueHandler singleReturnValueHandler() {
    return new SingleReturnValueHandler();
}
 
Example #16
Source File: HttpLoggingConfig.java    From spring-cloud-ribbon-extensions with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnClass(Logger.class)
public CommonsRequestLoggingFilter springLogging() {
    Logger logger = (Logger) LoggerFactory.getLogger(CommonsRequestLoggingFilter.class);
    logger.setLevel(Level.DEBUG);
    log.info("Http logging enabled {}.", properties);
    return requestLoggingFilter();
}
 
Example #17
Source File: SeataFeignClientAutoConfiguration.java    From spring-cloud-alibaba with Apache License 2.0 5 votes vote down vote up
@Bean
@Scope("prototype")
@ConditionalOnClass(name = "com.alibaba.csp.sentinel.SphU")
@ConditionalOnProperty(name = "feign.sentinel.enabled", havingValue = "true")
Feign.Builder feignSentinelBuilder(BeanFactory beanFactory) {
	return SeataSentinelFeignBuilder.builder(beanFactory);
}
 
Example #18
Source File: SentinelAutoConfiguration.java    From spring-cloud-alibaba with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
@ConditionalOnClass(name = "org.springframework.web.client.RestTemplate")
@ConditionalOnProperty(name = "resttemplate.sentinel.enabled", havingValue = "true",
		matchIfMissing = true)
public SentinelBeanPostProcessor sentinelBeanPostProcessor(
		ApplicationContext applicationContext) {
	return new SentinelBeanPostProcessor(applicationContext);
}
 
Example #19
Source File: SampleApplication.java    From spring-init with Apache License 2.0 5 votes vote down vote up
@ConditionalOnClass(name = "not.going.to.be.There")
@Bean
public CommandLineRunner runner(Bar bar) {
	return args -> {
		System.out.println("Message: " + message);
		System.out.println("Bar: " + bar);
		System.out.println("Foo: " + bar.getFoo());
	};
}
 
Example #20
Source File: CredHubOAuth2AutoConfiguration.java    From spring-credhub with Apache License 2.0 5 votes vote down vote up
/**
 * Create a {@code ClientRegistrationRepository} bean for use with an OAuth2-enabled
 * {@code CredHubTemplate}.
 * @return the {@code ClientRegistrationRepository}
 */
@Bean
@ConditionalOnMissingBean
@ConditionalOnClass(name = "javax.servlet.http.HttpServletRequest")
public ClientRegistrationRepository credHubClientRegistrationRepository() {
	List<ClientRegistration> registrations = new ArrayList<>(
			OAuth2ClientPropertiesRegistrationAdapter.getClientRegistrations(this.properties).values());
	return new InMemoryClientRegistrationRepository(registrations);
}
 
Example #21
Source File: GrayTrackWebMvcConfiguration.java    From spring-cloud-gray with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
@ConditionalOnClass(Filter.class)
public GrayTrackFilter grayTrackFilter(
        GrayTrackHolder grayTrackHolder, RequestLocalStorage requestLocalStorage) {
    return new GrayTrackFilter(grayTrackHolder, requestLocalStorage);
}
 
Example #22
Source File: ProductSvcShedLoadConfig.java    From cloud-espm-cloud-native with Apache License 2.0 5 votes vote down vote up
/**
 * It is used to register the tomcat valve with the tomcat container.
 * 
 * @return embeddedTomcat
 */
@Bean
@ConditionalOnClass({ Servlet.class, Tomcat.class })
public ServletWebServerFactory servletContainerWithSemaphoreRateLimiterValve() {
	TomcatServletWebServerFactory embeddedTomcat = new TomcatServletWebServerFactory();
	embeddedTomcat.addEngineValves(new ProductShedLoadSemaphoreValve(shedLoad));
	return embeddedTomcat;
}
 
Example #23
Source File: SpringCloudDubboAutoConfiguration.java    From spring-cloud-dubbo with Apache License 2.0 5 votes vote down vote up
@ConditionalOnProperty(name = BASE_PACKAGES_PROPERTY_NAME)
@ConditionalOnClass(ConfigurationPropertySources.class)
@Bean
public FeignClientToDubboProviderBeanPostProcessor feignClientToDubboProviderBeanPostProcessor(Environment environment) {
    Set<String> packagesToScan = environment.getProperty(BASE_PACKAGES_PROPERTY_NAME, Set.class, emptySet());
    return new FeignClientToDubboProviderBeanPostProcessor(packagesToScan);
}
 
Example #24
Source File: GrpcServerFactoryAutoConfiguration.java    From grpc-spring-boot-starter with MIT License 5 votes vote down vote up
/**
 * Creates a GrpcServerFactory using the shaded netty. This is the recommended default for gRPC.
 *
 * @param properties The properties used to configure the server.
 * @param serviceDiscoverer The discoverer used to identify the services that should be served.
 * @param serverConfigurers The server configurers that contain additional configuration for the server.
 * @return The shadedNettyGrpcServerFactory bean.
 */
@ConditionalOnClass(name = {"io.grpc.netty.shaded.io.netty.channel.Channel",
        "io.grpc.netty.shaded.io.grpc.netty.NettyServerBuilder"})
@Conditional(ConditionalOnInterprocessServer.class)
@Bean
public ShadedNettyGrpcServerFactory shadedNettyGrpcServerFactory(final GrpcServerProperties properties,
        final GrpcServiceDiscoverer serviceDiscoverer, final List<GrpcServerConfigurer> serverConfigurers) {
    final ShadedNettyGrpcServerFactory factory = new ShadedNettyGrpcServerFactory(properties, serverConfigurers);
    for (final GrpcServiceDefinition service : serviceDiscoverer.findGrpcServices()) {
        factory.addService(service);
    }
    return factory;
}
 
Example #25
Source File: GrpcClientAutoConfiguration.java    From grpc-spring-boot-starter with MIT License 5 votes vote down vote up
@ConditionalOnMissingBean(GrpcChannelFactory.class)
@ConditionalOnClass(name = {"io.grpc.netty.shaded.io.netty.channel.Channel",
        "io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder"})
@Bean
@Lazy
GrpcChannelFactory shadedNettyGrpcChannelFactory(final GrpcChannelsProperties properties,
        final GlobalClientInterceptorRegistry globalClientInterceptorRegistry,
        final List<GrpcChannelConfigurer> channelConfigurers) {
    final ShadedNettyChannelFactory channelFactory =
            new ShadedNettyChannelFactory(properties, globalClientInterceptorRegistry, channelConfigurers);
    final InProcessChannelFactory inProcessChannelFactory =
            new InProcessChannelFactory(properties, globalClientInterceptorRegistry, channelConfigurers);
    return new InProcessOrAlternativeChannelFactory(properties, inProcessChannelFactory, channelFactory);
}
 
Example #26
Source File: QuickFixJClientAutoConfiguration.java    From quickfixj-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnProperty(prefix = "quickfixj.client", name = "jmx-enabled", havingValue = "true")
@ConditionalOnClass(JmxExporter.class)
@ConditionalOnSingleCandidate(Initiator.class)
@ConditionalOnMissingBean(name = "clientInitiatorMBean", value = ObjectName.class)
public ObjectName clientInitiatorMBean(Initiator clientInitiator) {
	try {
		JmxExporter exporter = new JmxExporter();
		exporter.setRegistrationBehavior(REGISTRATION_REPLACE_EXISTING);
		return exporter.register(clientInitiator);
	} catch (Exception e) {
		throw new ConfigurationException(e.getMessage(), e);
	}
}
 
Example #27
Source File: GrpcClientAutoConfiguration.java    From grpc-spring-boot-starter with MIT License 5 votes vote down vote up
@ConditionalOnMissingBean(GrpcChannelFactory.class)
@ConditionalOnClass(name = {"io.netty.channel.Channel", "io.grpc.netty.NettyChannelBuilder"})
@Bean
@Lazy
GrpcChannelFactory nettyGrpcChannelFactory(final GrpcChannelsProperties properties,
        final GlobalClientInterceptorRegistry globalClientInterceptorRegistry,
        final List<GrpcChannelConfigurer> channelConfigurers) {
    final NettyChannelFactory channelFactory =
            new NettyChannelFactory(properties, globalClientInterceptorRegistry, channelConfigurers);
    final InProcessChannelFactory inProcessChannelFactory =
            new InProcessChannelFactory(properties, globalClientInterceptorRegistry, channelConfigurers);
    return new InProcessOrAlternativeChannelFactory(properties, inProcessChannelFactory, channelFactory);
}
 
Example #28
Source File: SpringSwagger2Configuration.java    From RestDoc with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnClass(FilterRegistrationBean.class)
@ConditionalOnMissingBean(RestDocConfig.HttpBasicAuth.class)
public FilterRegistrationBean<HttpBasicAuthFilter> swagger2HttpFilter(@Autowired(required = false) RestDocConfig restDocConfig) {
    RestDocConfig.HttpBasicAuth httpBasicAuth;
    if (restDocConfig == null || (httpBasicAuth = restDocConfig.getHttpBasicAuth()) == null)
        httpBasicAuth = new RestDocConfig.HttpBasicAuth(null, null);

    FilterRegistrationBean<HttpBasicAuthFilter> filterBean = new FilterRegistrationBean<>();
    HttpBasicAuthFilter authFilter = new HttpBasicAuthFilter(httpBasicAuth.getUsername(), httpBasicAuth.getPassword());
    filterBean.addUrlPatterns("/swagger2-ui/**","/swagger2.json","/swagger-ui/*","/swagger.json");
    filterBean.setFilter(authFilter);
    return filterBean;
}
 
Example #29
Source File: CredHubOAuth2AutoConfiguration.java    From spring-credhub with Apache License 2.0 5 votes vote down vote up
/**
 * Create a {@code ReactiveClientRegistrationRepository} bean for use with an
 * OAuth2-enabled {@code ReactiveCredHubTemplate}, in case
 * {@link ReactiveOAuth2ClientAutoConfiguration} doesn't configure one.
 * @return the {@code ReactiveClientRegistrationRepository}
 */
@Bean
@ConditionalOnMissingBean
@ConditionalOnClass(name = "org.springframework.web.reactive.function.client.WebClient")
public ReactiveClientRegistrationRepository credHubReactiveClientRegistrationRepository() {
	List<ClientRegistration> registrations = new ArrayList<>(
			OAuth2ClientPropertiesRegistrationAdapter.getClientRegistrations(this.properties).values());
	return new InMemoryReactiveClientRegistrationRepository(registrations);
}
 
Example #30
Source File: FormatterAutoConfiguration.java    From thinking-in-spring-boot-samples with Apache License 2.0 5 votes vote down vote up
/**
 * JSON 格式 {@link Formatter} Bean
 *
 * @return {@link JsonFormatter}
 */
@Bean
@ConditionalOnClass(name = "com.fasterxml.jackson.databind.ObjectMapper")
@ConditionalOnMissingBean(type = "com.fasterxml.jackson.databind.ObjectMapper")
public Formatter jsonFormatter() {
    return new JsonFormatter();
}