Java Code Examples for org.springframework.beans.factory.ObjectProvider#getIfUnique()
The following examples show how to use
org.springframework.beans.factory.ObjectProvider#getIfUnique() .
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: DefaultListableBeanFactory.java From spring-analysis-note with MIT License | 6 votes |
@Nullable private <T> T resolveBean(ResolvableType requiredType, @Nullable Object[] args, boolean nonUniqueAsNull) { NamedBeanHolder<T> namedBean = resolveNamedBean(requiredType, args, nonUniqueAsNull); if (namedBean != null) { return namedBean.getBeanInstance(); } BeanFactory parent = getParentBeanFactory(); if (parent instanceof DefaultListableBeanFactory) { return ((DefaultListableBeanFactory) parent).resolveBean(requiredType, args, nonUniqueAsNull); } else if (parent != null) { ObjectProvider<T> parentProvider = parent.getBeanProvider(requiredType); if (args != null) { return parentProvider.getObject(args); } else { return (nonUniqueAsNull ? parentProvider.getIfUnique() : parentProvider.getIfAvailable()); } } return null; }
Example 2
Source File: OkHttpRestTemplateAutoConfiguration.java From okhttp-spring-boot with MIT License | 6 votes |
@Bean @Lazy @ConditionalOnMissingBean public RestTemplateBuilder restTemplateBuilder(ObjectProvider<HttpMessageConverters> messageConverters, ObjectProvider<RestTemplateCustomizer> restTemplateCustomizers, ObjectProvider<RestTemplateRequestCustomizer<?>> restTemplateRequestCustomizers, OkHttpClient okHttpClient) { RestTemplateBuilder builder = new RestTemplateBuilder(); HttpMessageConverters converters = messageConverters.getIfUnique(); if (converters != null) { builder = builder.messageConverters(converters.getConverters()); } builder = addCustomizers(builder, restTemplateCustomizers, RestTemplateBuilder::customizers); builder = addCustomizers(builder, restTemplateRequestCustomizers, RestTemplateBuilder::requestCustomizers); builder = builder.requestFactory(() -> new OkHttp3ClientHttpRequestFactory(okHttpClient)); return builder; }
Example 3
Source File: DefaultListableBeanFactory.java From java-technology-stack with MIT License | 6 votes |
@Nullable private <T> T resolveBean(ResolvableType requiredType, @Nullable Object[] args, boolean nonUniqueAsNull) { NamedBeanHolder<T> namedBean = resolveNamedBean(requiredType, args, nonUniqueAsNull); if (namedBean != null) { return namedBean.getBeanInstance(); } BeanFactory parent = getParentBeanFactory(); if (parent instanceof DefaultListableBeanFactory) { return ((DefaultListableBeanFactory) parent).resolveBean(requiredType, args, nonUniqueAsNull); } else if (parent != null) { ObjectProvider<T> parentProvider = parent.getBeanProvider(requiredType); if (args != null) { return parentProvider.getObject(args); } else { return (nonUniqueAsNull ? parentProvider.getIfUnique() : parentProvider.getIfAvailable()); } } return null; }
Example 4
Source File: KafkaStreamsBinderSupportAutoConfiguration.java From spring-cloud-stream-binder-kafka with Apache License 2.0 | 6 votes |
@Bean @Conditional(FunctionDetectorCondition.class) public KafkaStreamsFunctionProcessor kafkaStreamsFunctionProcessor(BindingServiceProperties bindingServiceProperties, KafkaStreamsExtendedBindingProperties kafkaStreamsExtendedBindingProperties, KeyValueSerdeResolver keyValueSerdeResolver, KafkaStreamsBindingInformationCatalogue kafkaStreamsBindingInformationCatalogue, KafkaStreamsMessageConversionDelegate kafkaStreamsMessageConversionDelegate, ObjectProvider<CleanupConfig> cleanupConfig, StreamFunctionProperties streamFunctionProperties, @Qualifier("binderConfigurationProperties") KafkaStreamsBinderConfigurationProperties kafkaStreamsBinderConfigurationProperties, ObjectProvider<StreamsBuilderFactoryBeanCustomizer> customizerProvider, ConfigurableEnvironment environment) { return new KafkaStreamsFunctionProcessor(bindingServiceProperties, kafkaStreamsExtendedBindingProperties, keyValueSerdeResolver, kafkaStreamsBindingInformationCatalogue, kafkaStreamsMessageConversionDelegate, cleanupConfig.getIfUnique(), streamFunctionProperties, kafkaStreamsBinderConfigurationProperties, customizerProvider.getIfUnique(), environment); }
Example 5
Source File: KafkaStreamsBinderSupportAutoConfiguration.java From spring-cloud-stream-binder-kafka with Apache License 2.0 | 6 votes |
@Bean public KafkaStreamsStreamListenerSetupMethodOrchestrator kafkaStreamsStreamListenerSetupMethodOrchestrator( BindingServiceProperties bindingServiceProperties, KafkaStreamsExtendedBindingProperties kafkaStreamsExtendedBindingProperties, KeyValueSerdeResolver keyValueSerdeResolver, KafkaStreamsBindingInformationCatalogue kafkaStreamsBindingInformationCatalogue, KStreamStreamListenerParameterAdapter kafkaStreamListenerParameterAdapter, Collection<StreamListenerResultAdapter> streamListenerResultAdapters, ObjectProvider<CleanupConfig> cleanupConfig, ObjectProvider<StreamsBuilderFactoryBeanCustomizer> customizerProvider, ConfigurableEnvironment environment) { return new KafkaStreamsStreamListenerSetupMethodOrchestrator( bindingServiceProperties, kafkaStreamsExtendedBindingProperties, keyValueSerdeResolver, kafkaStreamsBindingInformationCatalogue, kafkaStreamListenerParameterAdapter, streamListenerResultAdapters, cleanupConfig.getIfUnique(), customizerProvider.getIfUnique(), environment); }
Example 6
Source File: OkHttpRestTemplateAutoConfiguration.java From okhttp-spring-boot with MIT License | 6 votes |
@Bean @Lazy @ConditionalOnMissingBean public RestTemplateBuilder restTemplateBuilder(ObjectProvider<HttpMessageConverters> messageConverters, ObjectProvider<RestTemplateCustomizer> restTemplateCustomizers, ObjectProvider<RestTemplateRequestCustomizer<?>> restTemplateRequestCustomizers, OkHttpClient okHttpClient) { RestTemplateBuilder builder = new RestTemplateBuilder(); HttpMessageConverters converters = messageConverters.getIfUnique(); if (converters != null) { builder = builder.messageConverters(converters.getConverters()); } builder = addCustomizers(builder, restTemplateCustomizers, RestTemplateBuilder::customizers); builder = addCustomizers(builder, restTemplateRequestCustomizers, RestTemplateBuilder::requestCustomizers); builder = builder.requestFactory(() -> new OkHttp3ClientHttpRequestFactory(okHttpClient)); return builder; }
Example 7
Source File: OkHttp3LoggingInterceptorAutoConfiguration.java From okhttp-spring-boot with MIT License | 5 votes |
@Bean @ApplicationInterceptor @ConditionalOnMissingBean public HttpLoggingInterceptor okHttp3LoggingInterceptor( OkHttp3LoggingInterceptorProperties properties, ObjectProvider<HttpLoggingInterceptor.Logger> logger ) { HttpLoggingInterceptor.Logger actualLogger = logger.getIfUnique(() -> HttpLoggingInterceptor.Logger.DEFAULT); HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor(actualLogger); httpLoggingInterceptor.level(properties.getLevel()); return httpLoggingInterceptor; }
Example 8
Source File: OkHttp3LoggingInterceptorAutoConfiguration.java From okhttp-spring-boot with MIT License | 5 votes |
@Bean @ApplicationInterceptor @ConditionalOnMissingBean public HttpLoggingInterceptor okHttp3LoggingInterceptor( OkHttp3LoggingInterceptorProperties properties, ObjectProvider<HttpLoggingInterceptor.Logger> logger ) { HttpLoggingInterceptor.Logger actualLogger = logger.getIfUnique(() -> HttpLoggingInterceptor.Logger.DEFAULT); HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor(actualLogger); httpLoggingInterceptor.level(properties.getLevel()); return httpLoggingInterceptor; }
Example 9
Source File: ApiBootQuartzAutoConfiguration.java From beihu-boot with Apache License 2.0 | 5 votes |
@Bean @Order(1) public SchedulerFactoryBeanCustomizer jobDataSourceCustomizer(ApiBootQuartzProperties properties, DataSource dataSource, @QuartzDataSource ObjectProvider<DataSource> quartzDataSource, ObjectProvider<PlatformTransactionManager> transactionManager) { return (schedulerFactoryBean) -> { if (properties.getJobStoreType() == JobStoreType.JDBC) { DataSource dataSourceToUse = this.getDataSource(dataSource, quartzDataSource); schedulerFactoryBean.setDataSource(dataSourceToUse); PlatformTransactionManager txManager = transactionManager.getIfUnique(); if (txManager != null) { schedulerFactoryBean.setTransactionManager(txManager); } } }; }
Example 10
Source File: AccessManagementService.java From feast with Apache License 2.0 | 5 votes |
@Autowired public AccessManagementService( FeastProperties feastProperties, ProjectRepository projectRepository, ObjectProvider<AuthorizationProvider> authorizationProvider) { this.projectRepository = projectRepository; // create default project if it does not yet exist. if (!projectRepository.existsById(Project.DEFAULT_NAME)) { this.createProject(Project.DEFAULT_NAME); } this.authorizationProvider = authorizationProvider.getIfUnique(); this.securityProperties = feastProperties.getSecurity(); }
Example 11
Source File: ReplyConfiguration.java From faster-framework-project with Apache License 2.0 | 5 votes |
public ReplyConfiguration(KafkaProperties properties, org.springframework.boot.autoconfigure.kafka.KafkaProperties kafkaProperties, ObjectProvider<RecordMessageConverter> messageConverter, ConsumerFactory<Object, Object> consumerFactory, ProducerFactory<Object, Object> producerFactory, ProducerListener<Object, Object> producerListener) { this.kafkaProperties = kafkaProperties; this.properties = properties; this.messageConverter = messageConverter.getIfUnique(); this.consumerFactory = consumerFactory; this.producerFactory = producerFactory; this.producerListener = producerListener; }
Example 12
Source File: ApiBootQuartzAutoConfiguration.java From api-boot with Apache License 2.0 | 5 votes |
@Bean @Order(1) public SchedulerFactoryBeanCustomizer jobDataSourceCustomizer(ApiBootQuartzProperties properties, DataSource dataSource, @QuartzDataSource ObjectProvider<DataSource> quartzDataSource, ObjectProvider<PlatformTransactionManager> transactionManager) { return (schedulerFactoryBean) -> { if (properties.getJobStoreType() == JobStoreType.JDBC) { DataSource dataSourceToUse = this.getDataSource(dataSource, quartzDataSource); schedulerFactoryBean.setDataSource(dataSourceToUse); PlatformTransactionManager txManager = transactionManager.getIfUnique(); if (txManager != null) { schedulerFactoryBean.setTransactionManager(txManager); } } }; }
Example 13
Source File: JobQuartzAutoConfiguration.java From spring-boot-starter-micro-job with Apache License 2.0 | 5 votes |
@Bean @Order(0) public SchedulerFactoryBeanCustomizer jobDataSourceCustomizer(QuartzProperties properties, DataSource dataSource, @QuartzDataSource ObjectProvider<DataSource> quartzDataSource, ObjectProvider<PlatformTransactionManager> transactionManager) { return (schedulerFactoryBean) -> { if (properties.getJobStoreType() == JobStoreType.JDBC) { DataSource dataSourceToUse = this.getDataSource(dataSource, quartzDataSource); schedulerFactoryBean.setDataSource(dataSourceToUse); PlatformTransactionManager txManager = (PlatformTransactionManager) transactionManager.getIfUnique(); if (txManager != null) { schedulerFactoryBean.setTransactionManager(txManager); } } }; }
Example 14
Source File: SampleConfiguration.java From spring-init with Apache License 2.0 | 4 votes |
@Bean public Bar bar(ObjectProvider<Foo> foo) { return new Bar(foo.getIfUnique()); }
Example 15
Source File: SampleConfiguration.java From spring-init with Apache License 2.0 | 4 votes |
@Bean public Bar bar(ObjectProvider<Foo> foo) { return new Bar(foo.getIfUnique()); }
Example 16
Source File: CmmnEngineAutoConfiguration.java From flowable-engine with Apache License 2.0 | 4 votes |
@Bean @ConditionalOnMissingBean public SpringCmmnEngineConfiguration cmmnEngineConfiguration(DataSource dataSource, PlatformTransactionManager platformTransactionManager, @Cmmn ObjectProvider<AsyncExecutor> asyncExecutorProvider, ObjectProvider<List<AutoDeploymentStrategy<CmmnEngine>>> cmmnAutoDeploymentStrategies) throws IOException { SpringCmmnEngineConfiguration configuration = new SpringCmmnEngineConfiguration(); List<Resource> resources = this.discoverDeploymentResources( cmmnProperties.getResourceLocation(), cmmnProperties.getResourceSuffixes(), cmmnProperties.isDeployResources() ); if (resources != null && !resources.isEmpty()) { configuration.setDeploymentResources(resources.toArray(new Resource[0])); configuration.setDeploymentName(cmmnProperties.getDeploymentName()); } AsyncExecutor asyncExecutor = asyncExecutorProvider.getIfUnique(); if (asyncExecutor != null) { configuration.setAsyncExecutor(asyncExecutor); } configureSpringEngine(configuration, platformTransactionManager); configureEngine(configuration, dataSource); configuration.setDeploymentName(defaultText(cmmnProperties.getDeploymentName(), configuration.getDeploymentName())); configuration.setDisableIdmEngine(!idmProperties.isEnabled()); configuration.setDisableEventRegistry(!eventProperties.isEnabled()); configuration.setAsyncExecutorActivate(flowableProperties.isAsyncExecutorActivate()); configuration.getHttpClientConfig().setUseSystemProperties(httpProperties.isUseSystemProperties()); configuration.getHttpClientConfig().setConnectionRequestTimeout(httpProperties.getConnectionRequestTimeout()); configuration.getHttpClientConfig().setConnectTimeout(httpProperties.getConnectTimeout()); configuration.getHttpClientConfig().setDisableCertVerify(httpProperties.isDisableCertVerify()); configuration.getHttpClientConfig().setRequestRetryLimit(httpProperties.getRequestRetryLimit()); configuration.getHttpClientConfig().setSocketTimeout(httpProperties.getSocketTimeout()); //TODO Can it have different then the Process engine? configuration.setHistoryLevel(flowableProperties.getHistoryLevel()); configuration.setEnableSafeCmmnXml(cmmnProperties.isEnableSafeXml()); configuration.setFormFieldValidationEnabled(flowableProperties.isFormFieldValidationEnabled()); // We cannot use orderedStream since we want to support Boot 1.5 which is on pre 5.x Spring List<AutoDeploymentStrategy<CmmnEngine>> deploymentStrategies = cmmnAutoDeploymentStrategies.getIfAvailable(); if (deploymentStrategies == null) { deploymentStrategies = new ArrayList<>(); } CommonAutoDeploymentProperties deploymentProperties = this.autoDeploymentProperties.deploymentPropertiesForEngine(ScopeTypes.CMMN); // Always add the out of the box auto deployment strategies as last deploymentStrategies.add(new DefaultAutoDeploymentStrategy(deploymentProperties)); deploymentStrategies.add(new SingleResourceAutoDeploymentStrategy(deploymentProperties)); deploymentStrategies.add(new ResourceParentFolderAutoDeploymentStrategy(deploymentProperties)); configuration.setDeploymentStrategies(deploymentStrategies); configuration.setEnableHistoryCleaning(flowableProperties.isEnableHistoryCleaning()); configuration.setHistoryCleaningTimeCycleConfig(flowableProperties.getHistoryCleaningCycle()); configuration.setCleanInstancesEndedAfterNumberOfDays(flowableProperties.getHistoryCleaningAfterDays()); return configuration; }
Example 17
Source File: FooService.java From tutorials with MIT License | 4 votes |
public FooService(ObjectProvider<FooRepository> repositoryProvider) { this.repository = repositoryProvider.getIfUnique(); }
Example 18
Source File: AbstractSpringEngineAutoConfiguration.java From flowable-engine with Apache License 2.0 | 3 votes |
/** * Get the Object provided by the {@code availableProvider}, otherwise get a unique object from {@code uniqueProvider}. * This can be used when we allow users to provide specific implementations per engine. For example to provide a specific * {@link org.springframework.core.task.TaskExecutor} and / or {@link org.flowable.spring.job.service.SpringRejectedJobsHandler} for the CMMN Async * Executor. Example: * <pre><code> * @Configuration * public class MyCustomConfiguration { * * @Bean * @Cmmn * public TaskExecutor cmmnTaskExecutor() { * return new MyCustomTaskExecutor() * } * * @@Bean * @Primary * public TaskExecutor primaryTaskExecutor() { * return new SimpleAsyncTaskExecutor() * } * * } * </code></pre> * Then when using: * <pre><code> * @Configuration * public class FlowableJobConfiguration { * * public SpringAsyncExecutor cmmnAsyncExecutor( * ObjectProvider<TaskExecutor> taskExecutor, * @Cmmn ObjectProvider<TaskExecutor> cmmnTaskExecutor * ) { * TaskExecutor executor = getIfAvailable( * cmmnTaskExecutor, * taskExecutor * ); * // executor is an instance of MyCustomTaskExecutor * } * * public SpringAsyncExecutor processAsyncExecutor( * ObjectProvider<TaskExecutor> taskExecutor, * @Process ObjectProvider<TaskExecutor> processTaskExecutor * ) { * TaskExecutor executor = getIfAvailable( * processTaskExecutor, * taskExecutor * ); * // executor is an instance of SimpleAsyncTaskExecutor * } * } * </code></pre> * * @param availableProvider * a provider that can provide an available object * @param uniqueProvider * a provider that would be used if there is no available object, but only if it is unique * @param <T> * the type of the object being provided * @return the available object from {@code availableProvider} if there, otherwise the unique object from {@code uniqueProvider} */ protected <T> T getIfAvailable(ObjectProvider<T> availableProvider, ObjectProvider<T> uniqueProvider) { // This can be implemented by using availableProvider.getIfAvailable(() -> uniqueProvider.getIfUnique()). However, that is only there in Spring 5 // and we want to be support Spring 4 with the starters as well T object = availableProvider.getIfAvailable(); if (object == null) { object = uniqueProvider.getIfUnique(); } return object; }