本文整理汇总了Java中org.springframework.beans.factory.config.ConfigurableBeanFactory类的典型用法代码示例。如果您正苦于以下问题:Java ConfigurableBeanFactory类的具体用法?Java ConfigurableBeanFactory怎么用?Java ConfigurableBeanFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConfigurableBeanFactory类属于org.springframework.beans.factory.config包,在下文中一共展示了ConfigurableBeanFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: copyConfigurationFrom
import org.springframework.beans.factory.config.ConfigurableBeanFactory; //导入依赖的package包/类
@Override
public void copyConfigurationFrom(ConfigurableBeanFactory otherFactory) {
Assert.notNull(otherFactory, "BeanFactory must not be null");
setBeanClassLoader(otherFactory.getBeanClassLoader());
setCacheBeanMetadata(otherFactory.isCacheBeanMetadata());
setBeanExpressionResolver(otherFactory.getBeanExpressionResolver());
if (otherFactory instanceof AbstractBeanFactory) {
AbstractBeanFactory otherAbstractFactory = (AbstractBeanFactory) otherFactory;
this.customEditors.putAll(otherAbstractFactory.customEditors);
this.propertyEditorRegistrars.addAll(otherAbstractFactory.propertyEditorRegistrars);
this.beanPostProcessors.addAll(otherAbstractFactory.beanPostProcessors);
this.hasInstantiationAwareBeanPostProcessors = this.hasInstantiationAwareBeanPostProcessors ||
otherAbstractFactory.hasInstantiationAwareBeanPostProcessors;
this.hasDestructionAwareBeanPostProcessors = this.hasDestructionAwareBeanPostProcessors ||
otherAbstractFactory.hasDestructionAwareBeanPostProcessors;
this.scopes.putAll(otherAbstractFactory.scopes);
this.securityContextProvider = otherAbstractFactory.securityContextProvider;
}
else {
setTypeConverter(otherFactory.getTypeConverter());
}
}
示例2: detectAnnotatedFactoryMethods
import org.springframework.beans.factory.config.ConfigurableBeanFactory; //导入依赖的package包/类
/**
* Detect relationships in annotated {@link Bean @Bean} Factory methods.
*
* @return Relationships detected from factory methods.
*/
protected Set<Relationship> detectAnnotatedFactoryMethods() {
Set<Relationship> result = new HashSet<>();
/* retrieve all beans declared in the application context */
String[] annotateBeans = applicationContext.getBeanDefinitionNames();
ConfigurableBeanFactory factory = applicationContext.getBeanFactory();
for (String beanName : annotateBeans) {
/* ... and get the bean definition of each declared beans */
Optional<MethodMetadata> metadata = getMethodMetadata(factory.getMergedBeanDefinition(beanName));
if (metadata.isPresent()) {
Set<Relationship> rel = detectMethodMetadata(metadata.get());
result.addAll(rel);
}
}
return result;
}
示例3: auditorAware
import org.springframework.beans.factory.config.ConfigurableBeanFactory; //导入依赖的package包/类
@Bean
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public AuditorAware<Username> auditorAware() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
log.debug("current authentication:" + authentication);
if (authentication == null || !authentication.isAuthenticated()) {
return () -> Optional.<Username>empty();
}
return () -> Optional.of(
Username.builder()
.username(((UserDetails) authentication.getPrincipal()).getUsername())
.build()
);
}
示例4: HandlerMethodService
import org.springframework.beans.factory.config.ConfigurableBeanFactory; //导入依赖的package包/类
public HandlerMethodService(ConversionService conversionService,
List<HandlerMethodArgumentResolver> customArgumentResolvers,
ObjectMapper objectMapper, ApplicationContext applicationContext) {
this.conversionService = conversionService;
this.parameterNameDiscoverer = new DefaultParameterNameDiscoverer();
this.argumentResolvers = new HandlerMethodArgumentResolverComposite();
ConfigurableBeanFactory beanFactory = ClassUtils.isAssignableValue(
ConfigurableApplicationContext.class, applicationContext)
? ((ConfigurableApplicationContext) applicationContext)
.getBeanFactory()
: null;
this.argumentResolvers.addResolver(
new HeaderMethodArgumentResolver(this.conversionService, beanFactory));
this.argumentResolvers.addResolver(new HeadersMethodArgumentResolver());
this.argumentResolvers.addResolver(new WampMessageMethodArgumentResolver());
this.argumentResolvers.addResolver(new PrincipalMethodArgumentResolver());
this.argumentResolvers.addResolver(new WampSessionIdMethodArgumentResolver());
this.argumentResolvers.addResolvers(customArgumentResolvers);
this.objectMapper = objectMapper;
}
示例5: setBeanFactory
import org.springframework.beans.factory.config.ConfigurableBeanFactory; //导入依赖的package包/类
@Override
public void setBeanFactory(BeanFactory beanFactory) {
if (!(beanFactory instanceof ConfigurableBeanFactory)) {
throw new IllegalStateException("ScriptFactoryPostProcessor doesn't work with a BeanFactory "
+ "which does not implement ConfigurableBeanFactory: " + beanFactory.getClass());
}
this.beanFactory = (ConfigurableBeanFactory) beanFactory;
// Required so that references (up container hierarchies) are correctly resolved.
this.scriptBeanFactory.setParentBeanFactory(this.beanFactory);
// Required so that all BeanPostProcessors, Scopes, etc become available.
this.scriptBeanFactory.copyConfigurationFrom(this.beanFactory);
// Filter out BeanPostProcessors that are part of the AOP infrastructure,
// since those are only meant to apply to beans defined in the original factory.
for (Iterator<BeanPostProcessor> it = this.scriptBeanFactory.getBeanPostProcessors().iterator(); it.hasNext();) {
if (it.next() instanceof AopInfrastructureBean) {
it.remove();
}
}
}
示例6: invokeAwareMethods
import org.springframework.beans.factory.config.ConfigurableBeanFactory; //导入依赖的package包/类
/**
* Invoke {@link ResourceLoaderAware}, {@link BeanClassLoaderAware} and
* {@link BeanFactoryAware} contracts if implemented by the given {@code bean}.
*/
private void invokeAwareMethods(Object importStrategyBean) {
if (importStrategyBean instanceof Aware) {
if (importStrategyBean instanceof EnvironmentAware) {
((EnvironmentAware) importStrategyBean).setEnvironment(this.environment);
}
if (importStrategyBean instanceof ResourceLoaderAware) {
((ResourceLoaderAware) importStrategyBean).setResourceLoader(this.resourceLoader);
}
if (importStrategyBean instanceof BeanClassLoaderAware) {
ClassLoader classLoader = (this.registry instanceof ConfigurableBeanFactory ?
((ConfigurableBeanFactory) this.registry).getBeanClassLoader() :
this.resourceLoader.getClassLoader());
((BeanClassLoaderAware) importStrategyBean).setBeanClassLoader(classLoader);
}
if (importStrategyBean instanceof BeanFactoryAware && this.registry instanceof BeanFactory) {
((BeanFactoryAware) importStrategyBean).setBeanFactory((BeanFactory) this.registry);
}
}
}
示例7: enhanceFactoryBean
import org.springframework.beans.factory.config.ConfigurableBeanFactory; //导入依赖的package包/类
/**
* Create a subclass proxy that intercepts calls to getObject(), delegating to the current BeanFactory
* instead of creating a new instance. These proxies are created only when calling a FactoryBean from
* within a Bean method, allowing for proper scoping semantics even when working against the FactoryBean
* instance directly. If a FactoryBean instance is fetched through the container via &-dereferencing,
* it will not be proxied. This too is aligned with the way XML configuration works.
*/
private Object enhanceFactoryBean(Class<?> fbClass, final ConfigurableBeanFactory beanFactory,
final String beanName) throws InstantiationException, IllegalAccessException {
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(fbClass);
enhancer.setUseFactory(false);
enhancer.setNamingPolicy(SpringNamingPolicy.INSTANCE);
enhancer.setCallback(new MethodInterceptor() {
@Override
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
if (method.getName().equals("getObject") && args.length == 0) {
return beanFactory.getBean(beanName);
}
return proxy.invokeSuper(obj, args);
}
});
return enhancer.create();
}
示例8: getResourceToInject
import org.springframework.beans.factory.config.ConfigurableBeanFactory; //导入依赖的package包/类
@Override
protected Object getResourceToInject(Object target, String requestingBeanName) {
if (StringUtils.hasLength(this.beanName)) {
if (beanFactory != null && beanFactory.containsBean(this.beanName)) {
// Local match found for explicitly specified local bean name.
Object bean = beanFactory.getBean(this.beanName, this.lookupType);
if (beanFactory instanceof ConfigurableBeanFactory) {
((ConfigurableBeanFactory) beanFactory).registerDependentBean(this.beanName, requestingBeanName);
}
return bean;
}
else if (this.isDefaultName && !StringUtils.hasLength(this.mappedName)) {
throw new NoSuchBeanDefinitionException(this.beanName,
"Cannot resolve 'beanName' in local BeanFactory. Consider specifying a general 'name' value instead.");
}
}
// JNDI name lookup - may still go to a local BeanFactory.
return getResource(this, requestingBeanName);
}
示例9: isFactoryBean
import org.springframework.beans.factory.config.ConfigurableBeanFactory; //导入依赖的package包/类
@Override
public boolean isFactoryBean(String name) throws NoSuchBeanDefinitionException {
String beanName = transformedBeanName(name);
Object beanInstance = getSingleton(beanName, false);
if (beanInstance != null) {
return (beanInstance instanceof FactoryBean);
}
else if (containsSingleton(beanName)) {
// null instance registered
return false;
}
// No singleton instance found -> check bean definition.
if (!containsBeanDefinition(beanName) && getParentBeanFactory() instanceof ConfigurableBeanFactory) {
// No bean definition found in this factory -> delegate to parent.
return ((ConfigurableBeanFactory) getParentBeanFactory()).isFactoryBean(name);
}
return isFactoryBean(beanName, getMergedLocalBeanDefinition(beanName));
}
示例10: destroyPrototypeInstance
import org.springframework.beans.factory.config.ConfigurableBeanFactory; //导入依赖的package包/类
/**
* Subclasses should call this method to destroy an obsolete prototype instance.
* @param target the bean instance to destroy
*/
protected void destroyPrototypeInstance(Object target) {
if (this.logger.isDebugEnabled()) {
this.logger.debug("Destroying instance of bean '" + getTargetBeanName() + "'");
}
if (getBeanFactory() instanceof ConfigurableBeanFactory) {
((ConfigurableBeanFactory) getBeanFactory()).destroyBean(getTargetBeanName(), target);
}
else if (target instanceof DisposableBean) {
try {
((DisposableBean) target).destroy();
}
catch (Throwable ex) {
logger.error("Couldn't invoke destroy method of bean with name '" + getTargetBeanName() + "'", ex);
}
}
}
示例11: buildInternalBeanFactory
import org.springframework.beans.factory.config.ConfigurableBeanFactory; //导入依赖的package包/类
/**
* Build an internal BeanFactory for resolving target beans.
* @param containingFactory the containing BeanFactory that originally defines the beans
* @return an independent internal BeanFactory to hold copies of some target beans
*/
protected DefaultListableBeanFactory buildInternalBeanFactory(ConfigurableBeanFactory containingFactory) {
// Set parent so that references (up container hierarchies) are correctly resolved.
DefaultListableBeanFactory internalBeanFactory = new DefaultListableBeanFactory(containingFactory);
// Required so that all BeanPostProcessors, Scopes, etc become available.
internalBeanFactory.copyConfigurationFrom(containingFactory);
// Filter out BeanPostProcessors that are part of the AOP infrastructure,
// since those are only meant to apply to beans defined in the original factory.
for (Iterator<BeanPostProcessor> it = internalBeanFactory.getBeanPostProcessors().iterator(); it.hasNext();) {
if (it.next() instanceof AopInfrastructureBean) {
it.remove();
}
}
return internalBeanFactory;
}
示例12: findDefaultEntityManagerFactory
import org.springframework.beans.factory.config.ConfigurableBeanFactory; //导入依赖的package包/类
/**
* Find a single default EntityManagerFactory in the Spring application context.
* @return the default EntityManagerFactory
* @throws NoSuchBeanDefinitionException if there is no single EntityManagerFactory in the context
*/
protected EntityManagerFactory findDefaultEntityManagerFactory(String requestingBeanName)
throws NoSuchBeanDefinitionException {
String[] beanNames =
BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this.beanFactory, EntityManagerFactory.class);
if (beanNames.length == 1) {
String unitName = beanNames[0];
EntityManagerFactory emf = (EntityManagerFactory) this.beanFactory.getBean(unitName);
if (this.beanFactory instanceof ConfigurableBeanFactory) {
((ConfigurableBeanFactory) this.beanFactory).registerDependentBean(unitName, requestingBeanName);
}
return emf;
}
else if (beanNames.length > 1) {
throw new NoUniqueBeanDefinitionException(EntityManagerFactory.class, beanNames);
}
else {
throw new NoSuchBeanDefinitionException(EntityManagerFactory.class);
}
}
示例13: afterPropertiesSet
import org.springframework.beans.factory.config.ConfigurableBeanFactory; //导入依赖的package包/类
@Override
public void afterPropertiesSet() throws Exception {
RequestMappingHandlerAdapter requestMappingHandlerAdapter = this.beanFactory.getBean(RequestMappingHandlerAdapter.class);
List<HandlerMethodArgumentResolver> argumentResolvers = new ArrayList<>();
List<HandlerMethodReturnValueHandler> returnValueHandlers = new ArrayList<>();
if (beanFactory instanceof ConfigurableBeanFactory) {
argumentResolvers.add(new WxArgumentResolver((ConfigurableBeanFactory) beanFactory));
} else {
argumentResolvers.add(new WxArgumentResolver(beanFactory.getBean(WxUserManager.class), beanFactory.getBean(WxUserProvider.class)));
}
returnValueHandlers.add(beanFactory.getBean(WxAsyncMessageReturnValueHandler.class));
argumentResolvers.addAll(requestMappingHandlerAdapter.getArgumentResolvers());
returnValueHandlers.addAll(requestMappingHandlerAdapter.getReturnValueHandlers());
requestMappingHandlerAdapter.setArgumentResolvers(argumentResolvers);
requestMappingHandlerAdapter.setReturnValueHandlers(returnValueHandlers);
}
示例14: initArgumentResolvers
import org.springframework.beans.factory.config.ConfigurableBeanFactory; //导入依赖的package包/类
protected List<HandlerMethodArgumentResolver> initArgumentResolvers() {
List<HandlerMethodArgumentResolver> resolvers = new ArrayList<HandlerMethodArgumentResolver>();
ConfigurableBeanFactory cbf = (this.beanFactory instanceof ConfigurableBeanFactory ?
(ConfigurableBeanFactory) this.beanFactory : null);
// Annotation-based argument resolution
resolvers.add(new HeaderMethodArgumentResolver(this.conversionService, cbf));
resolvers.add(new HeadersMethodArgumentResolver());
// Type-based argument resolution
resolvers.add(new MessageMethodArgumentResolver());
if (this.customArgumentResolvers != null) {
resolvers.addAll(this.customArgumentResolvers);
}
resolvers.add(new PayloadArgumentResolver(this.messageConverter, this.validator));
return resolvers;
}
示例15: invokeAwareMethods
import org.springframework.beans.factory.config.ConfigurableBeanFactory; //导入依赖的package包/类
/**
* Invoke {@link ResourceLoaderAware}, {@link BeanClassLoaderAware} and
* {@link BeanFactoryAware} contracts if implemented by the given {@code filter}.
*/
private void invokeAwareMethods(TypeFilter filter) {
if (filter instanceof Aware) {
if (filter instanceof EnvironmentAware) {
((EnvironmentAware) filter).setEnvironment(this.environment);
}
if (filter instanceof ResourceLoaderAware) {
((ResourceLoaderAware) filter).setResourceLoader(this.resourceLoader);
}
if (filter instanceof BeanClassLoaderAware) {
ClassLoader classLoader = (this.registry instanceof ConfigurableBeanFactory ?
((ConfigurableBeanFactory) this.registry).getBeanClassLoader() :
this.resourceLoader.getClassLoader());
((BeanClassLoaderAware) filter).setBeanClassLoader(classLoader);
}
if (filter instanceof BeanFactoryAware && this.registry instanceof BeanFactory) {
((BeanFactoryAware) filter).setBeanFactory((BeanFactory) this.registry);
}
}
}