Java Code Examples for org.springframework.beans.factory.ObjectProvider#getObject()

The following examples show how to use org.springframework.beans.factory.ObjectProvider#getObject() . 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 vote down vote up
@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: DefaultListableBeanFactory.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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 3
Source File: WebFluxTracingAutoConfiguration.java    From java-spring-web with Apache License 2.0 6 votes vote down vote up
@Bean
@ConditionalOnMissingBean(TracingWebFilter.class)
public TracingWebFilter traceFilter(
        final Tracer tracer,
        final WebTracingProperties webTracingProperties,
        final ObjectProvider<List<WebFluxSpanDecorator>> webFilterSpanDecorators,
        final @Qualifier("skipPattern") Pattern skipPattern
) {
    return new TracingWebFilter(
            tracer,
            webTracingProperties.getOrder(),
            skipPattern,
            webTracingProperties.getUrlPatterns(),
            webFilterSpanDecorators.getObject()
    );
}
 
Example 4
Source File: EclairAutoConfiguration.java    From eclair with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnSingleCandidate(Jaxb2Marshaller.class)
@ConditionalOnMissingBean(Jaxb2Printer.class)
@Order(100)
public Printer jaxb2Printer(ObjectProvider<Jaxb2Marshaller> jaxb2Marshaller) {
    Jaxb2Marshaller marshaller = jaxb2Marshaller.getObject();
    return new Jaxb2Printer(marshaller)
            .addPreProcessor(new JaxbElementWrapper(marshaller));
}
 
Example 5
Source File: EclairAutoConfiguration.java    From eclair with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnSingleCandidate(ObjectMapper.class)
@ConditionalOnMissingBean
@Order(200)
public JacksonPrinter jacksonPrinter(ObjectProvider<ObjectMapper> objectMapper) {
    return new JacksonPrinter(objectMapper.getObject());
}
 
Example 6
Source File: WebClientTracingAutoConfiguration.java    From java-spring-web with Apache License 2.0 5 votes vote down vote up
@Bean
public static TracingWebClientBeanPostProcessor tracingWebClientBeanPostProcessor(
        final Tracer tracer,
        final ObjectProvider<List<WebClientSpanDecorator>> webClientSpanDecorators
) {
    return new TracingWebClientBeanPostProcessor(
            tracer,
            webClientSpanDecorators.getObject()
    );
}
 
Example 7
Source File: HazelcastHttpSessionConfiguration.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Autowired
public void setHazelcastInstance(
		@SpringSessionHazelcastInstance ObjectProvider<HazelcastInstance> springSessionHazelcastInstance,
		ObjectProvider<HazelcastInstance> hazelcastInstance) {
	HazelcastInstance hazelcastInstanceToUse = springSessionHazelcastInstance.getIfAvailable();
	if (hazelcastInstanceToUse == null) {
		hazelcastInstanceToUse = hazelcastInstance.getObject();
	}
	this.hazelcastInstance = hazelcastInstanceToUse;
}
 
Example 8
Source File: JdbcHttpSessionConfiguration.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Autowired
public void setDataSource(@SpringSessionDataSource ObjectProvider<DataSource> springSessionDataSource,
		ObjectProvider<DataSource> dataSource) {
	DataSource dataSourceToUse = springSessionDataSource.getIfAvailable();
	if (dataSourceToUse == null) {
		dataSourceToUse = dataSource.getObject();
	}
	this.dataSource = dataSourceToUse;
}
 
Example 9
Source File: RedisHttpSessionConfiguration.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Autowired
public void setRedisConnectionFactory(
		@SpringSessionRedisConnectionFactory ObjectProvider<RedisConnectionFactory> springSessionRedisConnectionFactory,
		ObjectProvider<RedisConnectionFactory> redisConnectionFactory) {
	RedisConnectionFactory redisConnectionFactoryToUse = springSessionRedisConnectionFactory.getIfAvailable();
	if (redisConnectionFactoryToUse == null) {
		redisConnectionFactoryToUse = redisConnectionFactory.getObject();
	}
	this.redisConnectionFactory = redisConnectionFactoryToUse;
}
 
Example 10
Source File: RedisWebSessionConfiguration.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Autowired
public void setRedisConnectionFactory(
		@SpringSessionRedisConnectionFactory ObjectProvider<ReactiveRedisConnectionFactory> springSessionRedisConnectionFactory,
		ObjectProvider<ReactiveRedisConnectionFactory> redisConnectionFactory) {
	ReactiveRedisConnectionFactory redisConnectionFactoryToUse = springSessionRedisConnectionFactory
			.getIfAvailable();
	if (redisConnectionFactoryToUse == null) {
		redisConnectionFactoryToUse = redisConnectionFactory.getObject();
	}
	this.redisConnectionFactory = redisConnectionFactoryToUse;
}
 
Example 11
Source File: ConfigurationClassPostProcessorTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
public OverridingSingletonBeanConfig(ObjectProvider<SingletonBeanConfig> other) {
	other.getObject();
}
 
Example 12
Source File: ConfigurationClassPostProcessorTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
public OverridingSingletonBeanConfig(ObjectProvider<SingletonBeanConfig> other) {
	other.getObject();
}