當前位置: 首頁>>代碼示例>>Java>>正文


Java BeanFactory類代碼示例

本文整理匯總了Java中org.springframework.beans.factory.BeanFactory的典型用法代碼示例。如果您正苦於以下問題:Java BeanFactory類的具體用法?Java BeanFactory怎麽用?Java BeanFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


BeanFactory類屬於org.springframework.beans.factory包,在下文中一共展示了BeanFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: storageConsumer

import org.springframework.beans.factory.BeanFactory; //導入依賴的package包/類
@ConditionalOnBean(StorageComponent.class)
@Bean StorageConsumer storageConsumer(
    StorageComponent component,
    @Value("${zipkin.sparkstreaming.consumer.storage.fail-fast:true}") boolean failFast,
    BeanFactory bf
) throws IOException {
  if (failFast) checkStorageOk(component);
  Properties properties = extractZipkinProperties(bf.getBean(ConfigurableEnvironment.class));
  if (component instanceof V2StorageComponent) {
    zipkin2.storage.StorageComponent v2Storage = ((V2StorageComponent) component).delegate();
    if (v2Storage instanceof ElasticsearchHttpStorage) {
      return new ElasticsearchStorageConsumer(properties);
    } else if (v2Storage instanceof zipkin2.storage.cassandra.CassandraStorage) {
      return new Cassandra3StorageConsumer(properties);
    } else {
      throw new UnsupportedOperationException(v2Storage + " not yet supported");
    }
  } else if (component instanceof CassandraStorage) {
    return new CassandraStorageConsumer(properties);
  } else if (component instanceof MySQLStorage) {
    return new MySQLStorageConsumer(properties);
  } else {
    throw new UnsupportedOperationException(component + " not yet supported");
  }
}
 
開發者ID:openzipkin,項目名稱:zipkin-sparkstreaming,代碼行數:26,代碼來源:ZipkinStorageConsumerAutoConfiguration.java

示例2: getBeanFactory

import org.springframework.beans.factory.BeanFactory; //導入依賴的package包/類
/**
 * @return A found BeanFactory configuration
 */
private BeanFactory getBeanFactory()
{
    // If someone has set a resource name then we need to load that.
    if (configLocation != null && configLocation.length > 0)
    {
        log.info("Spring BeanFactory via ClassPathXmlApplicationContext using " + configLocation.length + "configLocations.");
        return new ClassPathXmlApplicationContext(configLocation);
    }

    ServletContext srvCtx = WebContextFactory.get().getServletContext();
    HttpServletRequest request = WebContextFactory.get().getHttpServletRequest();

    if (request != null)
    {
        return RequestContextUtils.getWebApplicationContext(request, srvCtx);
    }
    else
    {
        return WebApplicationContextUtils.getWebApplicationContext(srvCtx);
    }
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:25,代碼來源:SpringCreator.java

示例3: instantiate

import org.springframework.beans.factory.BeanFactory; //導入依賴的package包/類
@Override
public Object instantiate(RootBeanDefinition beanDefinition, String beanName, BeanFactory owner,
		final Constructor<?> ctor, Object[] args) {

	if (beanDefinition.getMethodOverrides().isEmpty()) {
		if (System.getSecurityManager() != null) {
			// use own privileged to change accessibility (when security is on)
			AccessController.doPrivileged(new PrivilegedAction<Object>() {
				@Override
				public Object run() {
					ReflectionUtils.makeAccessible(ctor);
					return null;
				}
			});
		}
		return BeanUtils.instantiateClass(ctor, args);
	}
	else {
		return instantiateWithMethodInjection(beanDefinition, beanName, owner, ctor, args);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:22,代碼來源:SimpleInstantiationStrategy.java

示例4: instantiateBean

import org.springframework.beans.factory.BeanFactory; //導入依賴的package包/類
/**
 * Instantiate the given bean using its default constructor.
 * @param beanName the name of the bean
 * @param mbd the bean definition for the bean
 * @return BeanWrapper for the new instance
 */
protected BeanWrapper instantiateBean(final String beanName, final RootBeanDefinition mbd) {
	try {
		Object beanInstance;
		final BeanFactory parent = this;
		if (System.getSecurityManager() != null) {
			beanInstance = AccessController.doPrivileged(new PrivilegedAction<Object>() {
				@Override
				public Object run() {
					return getInstantiationStrategy().instantiate(mbd, beanName, parent);
				}
			}, getAccessControlContext());
		}
		else {
			beanInstance = getInstantiationStrategy().instantiate(mbd, beanName, parent);
		}
		BeanWrapper bw = new BeanWrapperImpl(beanInstance);
		initBeanWrapper(bw);
		return bw;
	}
	catch (Throwable ex) {
		throw new BeanCreationException(mbd.getResourceDescription(), beanName, "Instantiation of bean failed", ex);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:30,代碼來源:AbstractAutowireCapableBeanFactory.java

示例5: getKeyFilter

import org.springframework.beans.factory.BeanFactory; //導入依賴的package包/類
/**
 * Creates the key filter lambda which is responsible to decide how the rate limit will be performed. The key
 * is the unique identifier like an IP address or a username.
 * 
 * @param url is used to generated a unique cache key
 * @param rateLimit the {@link RateLimit} configuration which holds the skip condition string
 * @param expressionParser is used to evaluate the expression if the filter key type is EXPRESSION.
 * @param beanFactory used to get full access to all java beans in the SpEl
 * @return should not been null. If no filter key type is matching a plain 1 is returned so that all requests uses the same key.
 */
public KeyFilter getKeyFilter(String url, RateLimit rateLimit, ExpressionParser expressionParser, BeanFactory beanFactory) {
	
	switch(rateLimit.getFilterKeyType()) {
	case IP:
		return (request) -> url + "-" + request.getRemoteAddr();
	case EXPRESSION:
		String expression = rateLimit.getExpression();
		if(StringUtils.isEmpty(expression)) {
			throw new MissingKeyFilterExpressionException();
		}
		StandardEvaluationContext context = new StandardEvaluationContext();
		context.setBeanResolver(new BeanFactoryResolver(beanFactory));
		return  (request) -> {
			//TODO performance problem - how can the request object reused in the expression without setting it as a rootObject
			Expression expr = expressionParser.parseExpression(rateLimit.getExpression()); 
			final String value = expr.getValue(context, request, String.class);
			return url + "-" + value;
		};
	
	}
	return (request) -> url + "-" + "1";
}
 
開發者ID:MarcGiffing,項目名稱:bucket4j-spring-boot-starter,代碼行數:33,代碼來源:Bucket4JBaseConfiguration.java

示例6: skipCondition

import org.springframework.beans.factory.BeanFactory; //導入依賴的package包/類
/**
 * Creates the lambda for the skip condition which will be evaluated on each request
 * 
 * @param rateLimit the {@link RateLimit} configuration which holds the skip condition string
 * @param expressionParser is used to evaluate the skip expression
 * @param beanFactory used to get full access to all java beans in the SpEl
 * @return the lamdba condition which will be evaluated lazy - null if there is no condition available.
 */
public Condition skipCondition(RateLimit rateLimit, ExpressionParser expressionParser, BeanFactory beanFactory) {
	StandardEvaluationContext context = new StandardEvaluationContext();
	context.setBeanResolver(new BeanFactoryResolver(beanFactory));
	
	if(rateLimit.getSkipCondition() != null) {
		return  (request) -> {
			Expression expr = expressionParser.parseExpression(rateLimit.getSkipCondition()); 
			Boolean value = expr.getValue(context, request, Boolean.class);
			return value;
		};
	}
	return null;
}
 
開發者ID:MarcGiffing,項目名稱:bucket4j-spring-boot-starter,代碼行數:22,代碼來源:Bucket4JBaseConfiguration.java

示例7: autowire

import org.springframework.beans.factory.BeanFactory; //導入依賴的package包/類
@Override
public Object autowire(Class<?> beanClass, int autowireMode, boolean dependencyCheck) throws BeansException {
	// Use non-singleton bean definition, to avoid registering bean as dependent bean.
	final RootBeanDefinition bd = new RootBeanDefinition(beanClass, autowireMode, dependencyCheck);
	bd.setScope(BeanDefinition.SCOPE_PROTOTYPE);
	if (bd.getResolvedAutowireMode() == AUTOWIRE_CONSTRUCTOR) {
		return autowireConstructor(beanClass.getName(), bd, null, null).getWrappedInstance();
	}
	else {
		Object bean;
		final BeanFactory parent = this;
		if (System.getSecurityManager() != null) {
			bean = AccessController.doPrivileged(new PrivilegedAction<Object>() {
				@Override
				public Object run() {
					return getInstantiationStrategy().instantiate(bd, null, parent);
				}
			}, getAccessControlContext());
		}
		else {
			bean = getInstantiationStrategy().instantiate(bd, null, parent);
		}
		populateBean(beanClass.getName(), bd, new BeanWrapperImpl(bean));
		return bean;
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:27,代碼來源:AbstractAutowireCapableBeanFactory.java

示例8: findParentDefinition

import org.springframework.beans.factory.BeanFactory; //導入依賴的package包/類
private BeanDefinition findParentDefinition(String parentName, BeanDefinitionRegistry registry)
{   
    if (registry != null) 
    {
        if (registry.containsBeanDefinition(parentName)) 
        {
            return registry.getBeanDefinition(parentName);
        } 
        else if (registry instanceof HierarchicalBeanFactory) 
        {
            // Try to get parent definition from the parent BeanFactory. This could return null
            BeanFactory parentBeanFactory = ((HierarchicalBeanFactory)registry).getParentBeanFactory();
            return findParentDefinition(parentName, (BeanDefinitionRegistry)parentBeanFactory);
        } 
    }
    
    // we've exhausted all possibilities        
    return null;
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:20,代碼來源:DwrNamespaceHandler.java

示例9: postProcessBeanFactory

import org.springframework.beans.factory.BeanFactory; //導入依賴的package包/類
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
	if (isLogEnabled()) {
		String[] beanNames = beanFactory.getBeanDefinitionNames();
		for (String beanName : beanNames) {
			String nameToLookup = beanName;
			if (beanFactory.isFactoryBean(beanName)) {
				nameToLookup = BeanFactory.FACTORY_BEAN_PREFIX + beanName;
			}
			Class<?> beanType = ClassUtils.getUserClass(beanFactory.getType(nameToLookup));
			if (beanType != null && beanType.isAnnotationPresent(Deprecated.class)) {
				BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
				logDeprecatedBean(beanName, beanType, beanDefinition);
			}
		}
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:18,代碼來源:DeprecatedBeanWarner.java

示例10: testAppContextClassHierarchy

import org.springframework.beans.factory.BeanFactory; //導入依賴的package包/類
public void testAppContextClassHierarchy() {
	Class<?>[] clazz =
			ClassUtils.getClassHierarchy(OsgiBundleXmlApplicationContext.class, ClassUtils.ClassSet.ALL_CLASSES);

       //Closeable.class,
	Class<?>[] expected =
			new Class<?>[] { OsgiBundleXmlApplicationContext.class,
					AbstractDelegatedExecutionApplicationContext.class, AbstractOsgiBundleApplicationContext.class,
					AbstractRefreshableApplicationContext.class, AbstractApplicationContext.class,
					DefaultResourceLoader.class, ResourceLoader.class,
					AutoCloseable.class,
					DelegatedExecutionOsgiBundleApplicationContext.class,
					ConfigurableOsgiBundleApplicationContext.class, ConfigurableApplicationContext.class,
					ApplicationContext.class, Lifecycle.class, Closeable.class, EnvironmentCapable.class, ListableBeanFactory.class,
					HierarchicalBeanFactory.class, ApplicationEventPublisher.class, ResourcePatternResolver.class,
					MessageSource.class, BeanFactory.class, DisposableBean.class };

	assertTrue(compareArrays(expected, clazz));
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:20,代碼來源:ClassUtilsTest.java

示例11: contextMatch

import org.springframework.beans.factory.BeanFactory; //導入依賴的package包/類
private FuzzyBoolean contextMatch(Class<?> targetType) {
	String advisedBeanName = getCurrentProxiedBeanName();
	if (advisedBeanName == null) {  // no proxy creation in progress
		// abstain; can't return YES, since that will make pointcut with negation fail
		return FuzzyBoolean.MAYBE;
	}
	if (BeanFactoryUtils.isGeneratedBeanName(advisedBeanName)) {
		return FuzzyBoolean.NO;
	}
	if (targetType != null) {
		boolean isFactory = FactoryBean.class.isAssignableFrom(targetType);
		return FuzzyBoolean.fromBoolean(
				matchesBeanName(isFactory ? BeanFactory.FACTORY_BEAN_PREFIX + advisedBeanName : advisedBeanName));
	}
	else {
		return FuzzyBoolean.fromBoolean(matchesBeanName(advisedBeanName) ||
				matchesBeanName(BeanFactory.FACTORY_BEAN_PREFIX + advisedBeanName));
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:20,代碼來源:AspectJExpressionPointcut.java

示例12: HandlerMethod

import org.springframework.beans.factory.BeanFactory; //導入依賴的package包/類
/**
 * Create an instance from a bean name, a method, and a {@code BeanFactory}.
 * The method {@link #createWithResolvedBean()} may be used later to
 * re-create the {@code HandlerMethod} with an initialized the bean.
 */
public HandlerMethod(String beanName, BeanFactory beanFactory, Method method) {
	Assert.hasText(beanName, "Bean name is required");
	Assert.notNull(beanFactory, "BeanFactory is required");
	Assert.notNull(method, "Method is required");
	Assert.isTrue(beanFactory.containsBean(beanName),
			"BeanFactory [" + beanFactory + "] does not contain bean [" + beanName + "]");
	this.bean = beanName;
	this.beanFactory = beanFactory;
	this.method = method;
	this.bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
	this.parameters = initMethodParameters();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:18,代碼來源:HandlerMethod.java

示例13: jButton1ActionPerformed

import org.springframework.beans.factory.BeanFactory; //導入依賴的package包/類
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
	String groupname = jComboBox1.getSelectedItem().toString();
	if (!groupname.equals(users.getGroupname())) {
		BeanFactory beanFactory = new DataBaseDataSource().getDataFactory();
		RegistrationDAO registrationDAO = (RegistrationDAO) beanFactory
				.getBean("registrationDAO");
		users.setNewgroupname(groupname);
		System.out.println(groupname);
		boolean b = registrationDAO.usergroupcount(users);
		File f = new File("groups");
		boolean delete = f.delete();
		System.out.println("file deleted " + delete);
		new GroupMemberchange(users).setVisible(true);

	} else {

	}

}
 
開發者ID:cyberheartmi9,項目名稱:Mona-Secure-Multi-Owner-Data-Sharing-for-Dynamic-Group-in-the-Cloud,代碼行數:20,代碼來源:GroupMemberchange.java

示例14: invokeAwareMethods

import org.springframework.beans.factory.BeanFactory; //導入依賴的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);
		}
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:24,代碼來源:ConfigurationClassParser.java

示例15: setBeanFactory

import org.springframework.beans.factory.BeanFactory; //導入依賴的package包/類
/**
 * Set the owning BeanFactory. We need to save a reference so that we can
 * use the {@code getBean} method on every invocation.
 */
@Override
public void setBeanFactory(BeanFactory beanFactory) {
	if (this.targetBeanName == null) {
		throw new IllegalStateException("Property'targetBeanName' is required");
	}
	this.beanFactory = beanFactory;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:12,代碼來源:AbstractBeanFactoryBasedTargetSource.java


注:本文中的org.springframework.beans.factory.BeanFactory類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。