当前位置: 首页>>代码示例>>Java>>正文


Java GenericBeanDefinition.setBeanClass方法代码示例

本文整理汇总了Java中org.springframework.beans.factory.support.GenericBeanDefinition.setBeanClass方法的典型用法代码示例。如果您正苦于以下问题:Java GenericBeanDefinition.setBeanClass方法的具体用法?Java GenericBeanDefinition.setBeanClass怎么用?Java GenericBeanDefinition.setBeanClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.beans.factory.support.GenericBeanDefinition的用法示例。


在下文中一共展示了GenericBeanDefinition.setBeanClass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doScan

import org.springframework.beans.factory.support.GenericBeanDefinition; //导入方法依赖的package包/类
@Override
public Set<BeanDefinitionHolder> doScan(String... basePackages) {
    Set<BeanDefinitionHolder> beanDefinitions = super.doScan(basePackages);
    if (beanDefinitions.isEmpty()) {
        logger.warn("No  mapper was found in '" + Arrays.toString(basePackages) + "' package. Please check your configuration.");
    } else {
        for (BeanDefinitionHolder holder : beanDefinitions) {
            GenericBeanDefinition definition = (GenericBeanDefinition) holder.getBeanDefinition();
            if (logger.isDebugEnabled()) {
                logger.debug("Creating MapperFactoryBean with name '" + holder.getBeanName() + "' and '" + definition.getBeanClassName()
                        + "' mapperInterface");
            }
            definition.getPropertyValues().add("mapperProxy", getRegistry().getBeanDefinition("mapperProxy"));
            definition.getPropertyValues().add("mapperInterface", definition.getBeanClassName());
            definition.setBeanClass(MapperFactoryBean.class);
            definition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE);
        }
    }
    return beanDefinitions;
}
 
开发者ID:lftao,项目名称:jkami,代码行数:21,代码来源:ClassPathMapperScanner.java

示例2: reloadBean

import org.springframework.beans.factory.support.GenericBeanDefinition; //导入方法依赖的package包/类
/**
 * Reloading spring bean
 *
 * @param clazz
 * @param initMethod
 * @param destroyMethod
 * @throws Exception
 */
public void reloadBean(Class<?> clazz, String initMethod, String destroyMethod) throws Exception {

    BeanDefinitionRegistry beanDefinitionRegistry = ((BeanDefinitionRegistry) this.beanFactory);
    String beanName = clazz.getSimpleName().substring(0, 1).toLowerCase() + clazz.getSimpleName().substring(1);

    GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
    beanDefinition.setBeanClass(clazz);
    beanDefinition.setAutowireCandidate(true);

    if (StringUtils.isNotBlank(initMethod)) {
        beanDefinition.setInitMethodName(initMethod);
    }

    if (StringUtils.isNotBlank(destroyMethod)) {
        beanDefinition.setDestroyMethodName(destroyMethod);
    }

    if (beanDefinitionRegistry.containsBeanDefinition(beanName)) {
        beanDefinitionRegistry.removeBeanDefinition(beanName);
    }

    beanDefinitionRegistry.registerBeanDefinition(beanName, beanDefinition);
    applicationContext.getBean(beanName);
}
 
开发者ID:speedyproject,项目名称:dcmp,代码行数:33,代码来源:SpringBeanFactory.java

示例3: postProcessBeanFactory

import org.springframework.beans.factory.support.GenericBeanDefinition; //导入方法依赖的package包/类
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    BeanDefinitionRegistry registry=(BeanDefinitionRegistry)beanFactory;
    CuratorFramework curatorFramework = beanFactory.getBean(CuratorFramework.class);
    ServiceRouter serviceRouter = beanFactory.getBean(ServiceRouter.class);
    for(Class clazz:list){
        GenericBeanDefinition definition=(GenericBeanDefinition) BeanDefinitionBuilder.genericBeanDefinition(clazz).getBeanDefinition();
        definition.getPropertyValues().addPropertyValue("innerClass",clazz);
        definition.getPropertyValues().addPropertyValue("factory",beanFactory);
        ServiceApi serviceApi = map.get(clazz.getName());
        definition.getPropertyValues().addPropertyValue("proccessName",serviceApi.getName());

        String path = "/"+clazz.getName()+"/"+ (serviceApi!=null ? serviceApi.getVersion() :
                ThriftConstant.DEFAULT_VERSION);
        ServiceDiscover serviceDiscover = new ZookeeperServiceDiscover(curatorFramework, path);

        definition.getPropertyValues().addPropertyValue("serverManager",
                new ServerManager(serviceDiscover, serviceRouter));

        definition.setBeanClass(ProxyFactoryBean.class);
        definition.setDestroyMethodName("close");
        registry.registerBeanDefinition(clazz.getName(), definition);
    }

}
 
开发者ID:somewhereMrli,项目名称:albedo-thrift,代码行数:25,代码来源:ServiceStarter.java

示例4: testQualifiedByParentValue

import org.springframework.beans.factory.support.GenericBeanDefinition; //导入方法依赖的package包/类
@Test
public void testQualifiedByParentValue() {
	StaticApplicationContext parent = new StaticApplicationContext();
	GenericBeanDefinition parentLarry = new GenericBeanDefinition();
	parentLarry.setBeanClass(Person.class);
	parentLarry.getPropertyValues().add("name", "ParentLarry");
	parentLarry.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "parentLarry"));
	parent.registerBeanDefinition("someLarry", parentLarry);
	GenericBeanDefinition otherLarry = new GenericBeanDefinition();
	otherLarry.setBeanClass(Person.class);
	otherLarry.getPropertyValues().add("name", "OtherLarry");
	otherLarry.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "otherLarry"));
	parent.registerBeanDefinition("someOtherLarry", otherLarry);
	parent.refresh();

	StaticApplicationContext context = new StaticApplicationContext(parent);
	BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
	reader.loadBeanDefinitions(CONFIG_LOCATION);
	context.registerSingleton("testBean", QualifiedByParentValueTestBean.class);
	context.refresh();
	QualifiedByParentValueTestBean testBean = (QualifiedByParentValueTestBean) context.getBean("testBean");
	Person person = testBean.getLarry();
	assertEquals("ParentLarry", person.getName());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:QualifierAnnotationTests.java

示例5: doScan

import org.springframework.beans.factory.support.GenericBeanDefinition; //导入方法依赖的package包/类
@Override
public Set<BeanDefinitionHolder> doScan(String... basePackages) {
	Set<BeanDefinitionHolder> beanDefinitions = super.doScan(basePackages);
	for (BeanDefinitionHolder holder : beanDefinitions) {
		GenericBeanDefinition definition = (GenericBeanDefinition) holder.getBeanDefinition();
		String id = getValue(definition);
		if (StringUtils.isEmpty(id)) {
			id = holder.getBeanName();
		}
		String className = holder.getBeanDefinition().getBeanClassName();
		// logger.info("holder:" + holder.getBeanName() + " className:" + className);
		OptionData.load(id, className);
		definition.getPropertyValues().add("innerClassName", definition.getBeanClassName());
		definition.setBeanClass(OptionFactoryBean.class);
	}
	return beanDefinitions;
}
 
开发者ID:tanhaichao,项目名称:leopard,代码行数:18,代码来源:OptionScanner.java

示例6: initializeForProvider

import org.springframework.beans.factory.support.GenericBeanDefinition; //导入方法依赖的package包/类
public void initializeForProvider(ConfigurableListableBeanFactory beanFactory, String application, String refBeanName)
		throws BeansException {
	BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;

	// <dubbo:service interface="org.bytesoft.bytejta.supports.wire.RemoteCoordinator" group="org-bytesoft-bytetcc"
	// ref="dispatcherCoordinator" filter="compensable" loadbalance="compensable" cluster="failfast" />
	GenericBeanDefinition beanDef = new GenericBeanDefinition();
	beanDef.setBeanClass(com.alibaba.dubbo.config.spring.ServiceBean.class);

	MutablePropertyValues mpv = beanDef.getPropertyValues();
	mpv.addPropertyValue("interface", RemoteCoordinator.class.getName());
	mpv.addPropertyValue("ref", new RuntimeBeanReference(refBeanName));
	mpv.addPropertyValue("cluster", "failfast");
	mpv.addPropertyValue("loadbalance", "compensable");
	mpv.addPropertyValue("filter", "compensable");
	mpv.addPropertyValue("group", "org-bytesoft-bytetcc");
	mpv.addPropertyValue("retries", "0");
	mpv.addPropertyValue("timeout", "6000");

	String skeletonBeanId = String.format("[email protected]%s", RemoteCoordinator.class.getName());
	registry.registerBeanDefinition(skeletonBeanId, beanDef);
}
 
开发者ID:liuyangming,项目名称:ByteTCC,代码行数:23,代码来源:CompensableConfigPostProcessor.java

示例7: testScanWithExplicitSqlSessionTemplate

import org.springframework.beans.factory.support.GenericBeanDefinition; //导入方法依赖的package包/类
@Test
public void testScanWithExplicitSqlSessionTemplate() throws Exception {
  GenericBeanDefinition definition = new GenericBeanDefinition();
  definition.setBeanClass(SqlSessionTemplate.class);
  ConstructorArgumentValues constructorArgs = new ConstructorArgumentValues();
  constructorArgs.addGenericArgumentValue(new RuntimeBeanReference("sqlSessionFactory"));
  definition.setConstructorArgumentValues(constructorArgs);
  applicationContext.registerBeanDefinition("sqlSessionTemplate", definition);

  applicationContext.register(AppConfigWithSqlSessionTemplate.class);
  
  startContext();

  // all interfaces with methods should be loaded
  applicationContext.getBean("mapperInterface");
  applicationContext.getBean("mapperSubinterface");
  applicationContext.getBean("mapperChildInterface");
  applicationContext.getBean("annotatedMapper");
  
}
 
开发者ID:lindzh,项目名称:mybatis-spring-1.2.2,代码行数:21,代码来源:MapperScanTest.java

示例8: overrideBeanClass

import org.springframework.beans.factory.support.GenericBeanDefinition; //导入方法依赖的package包/类
/**
 * Override a {@link BeanDefinition} in the given context, effectively replacing the bean that will be created.
 * 
 * This has to be called before the context is {@link GenericApplicationContext#refresh()}ed.
 * 
 * @param ctx
 *          The context to work on.
 * @param overriddenBeanClass
 *          Class of the bean that should be overridden.
 * @param newBeanClass
 *          Class of bean that should be used instead.
 */
public static void overrideBeanClass(GenericApplicationContext ctx, Class<?> overriddenBeanClass, Class<?> newBeanClass) {
  String overrideBeanDefName = null;
  for (String beanDefinitionName : ctx.getBeanFactory().getBeanDefinitionNames()) {
    if (ctx.getBeanFactory().getBeanDefinition(beanDefinitionName).getBeanClassName()
        .equals(overriddenBeanClass.getName())) {
      overrideBeanDefName = beanDefinitionName;
      break;
    }
  }

  GenericBeanDefinition overridingBeanDef =
      (GenericBeanDefinition) ((GenericBeanDefinition) ctx.getBeanFactory().getBeanDefinition(overrideBeanDefName))
          .cloneBeanDefinition();
  overridingBeanDef.setBeanClass(newBeanClass);
  ctx.registerBeanDefinition(overrideBeanDefName, overridingBeanDef);
}
 
开发者ID:diqube,项目名称:diqube,代码行数:29,代码来源:TestContextOverrideBean.java

示例9: testNameGenerator

import org.springframework.beans.factory.support.GenericBeanDefinition; //导入方法依赖的package包/类
@Test
public void testNameGenerator() {
  GenericBeanDefinition definition = new GenericBeanDefinition();
  definition.setBeanClass(BeanNameGenerator.class);
  applicationContext.registerBeanDefinition("beanNameGenerator", definition);

  applicationContext.getBeanDefinition("mapperScanner").getPropertyValues().add(
      "nameGenerator", new RuntimeBeanReference("beanNameGenerator"));

  startContext();

  // only child inferfaces should be loaded and named with its class name
  applicationContext.getBean(MapperInterface.class.getName());
  applicationContext.getBean(MapperSubinterface.class.getName());
  applicationContext.getBean(MapperChildInterface.class.getName());
  applicationContext.getBean(AnnotatedMapper.class.getName());
}
 
开发者ID:lindzh,项目名称:mybatis-spring-1.2.2,代码行数:18,代码来源:MapperScannerConfigurerTest.java

示例10: testScanWithExplicitSqlSessionFactoryViaPlaceholder

import org.springframework.beans.factory.support.GenericBeanDefinition; //导入方法依赖的package包/类
@Test
public void testScanWithExplicitSqlSessionFactoryViaPlaceholder() throws Exception {
  setupSqlSessionFactory("sqlSessionFactory2");

  // use a property placeholder for the session factory name
  applicationContext.getBeanDefinition("mapperScanner").getPropertyValues().add(
      "sqlSessionFactoryBeanName", "${sqlSessionFactoryBeanNameProperty}");

  Properties props = new java.util.Properties();
  props.put("sqlSessionFactoryBeanNameProperty", "sqlSessionFactory2");

  GenericBeanDefinition propertyDefinition = new GenericBeanDefinition();
  propertyDefinition.setBeanClass(PropertyPlaceholderConfigurer.class);
  propertyDefinition.getPropertyValues().add("properties", props);

  applicationContext.registerBeanDefinition("propertiesPlaceholder", propertyDefinition);

  testInterfaceScan();
}
 
开发者ID:lindzh,项目名称:mybatis-spring-1.2.2,代码行数:20,代码来源:MapperScannerConfigurerTest.java

示例11: initializeForProvider

import org.springframework.beans.factory.support.GenericBeanDefinition; //导入方法依赖的package包/类
public void initializeForProvider(ConfigurableListableBeanFactory beanFactory, String application, String refBeanName)
		throws BeansException {
	BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;

	GenericBeanDefinition beanDef = new GenericBeanDefinition();
	beanDef.setBeanClass(com.alibaba.dubbo.config.spring.ServiceBean.class);

	MutablePropertyValues mpv = beanDef.getPropertyValues();
	mpv.addPropertyValue("interface", RemoteCoordinator.class.getName());
	mpv.addPropertyValue("ref", new RuntimeBeanReference(refBeanName));
	mpv.addPropertyValue("cluster", "failfast");
	mpv.addPropertyValue("loadbalance", "transaction");
	mpv.addPropertyValue("filter", "transaction");
	mpv.addPropertyValue("group", "org.bytesoft.bytejta");
	mpv.addPropertyValue("retries", "0");
	mpv.addPropertyValue("timeout", "6000");

	String skeletonBeanId = String.format("[email protected]%s", RemoteCoordinator.class.getName());
	registry.registerBeanDefinition(skeletonBeanId, beanDef);
}
 
开发者ID:liuyangming,项目名称:ByteJTA,代码行数:21,代码来源:TransactionConfigPostProcessor.java

示例12: configurationPropertiesWithFactoryBean

import org.springframework.beans.factory.support.GenericBeanDefinition; //导入方法依赖的package包/类
@Test
public void configurationPropertiesWithFactoryBean() throws Exception {
	ConfigurationPropertiesWithFactoryBean.factoryBeanInit = false;
	this.context = new AnnotationConfigApplicationContext() {
		@Override
		protected void onRefresh() throws BeansException {
			assertFalse("Init too early",
					ConfigurationPropertiesWithFactoryBean.factoryBeanInit);
			super.onRefresh();
		}
	};
	this.context.register(ConfigurationPropertiesWithFactoryBean.class);
	GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
	beanDefinition.setBeanClass(FactoryBeanTester.class);
	beanDefinition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE);
	this.context.registerBeanDefinition("test", beanDefinition);
	this.context.refresh();
	assertTrue("No init", ConfigurationPropertiesWithFactoryBean.factoryBeanInit);
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:20,代码来源:ConfigurationPropertiesBindingPostProcessorTests.java

示例13: setupContext

import org.springframework.beans.factory.support.GenericBeanDefinition; //导入方法依赖的package包/类
@Before
public void setupContext() {
  applicationContext = new GenericApplicationContext();

  // add the mapper scanner as a bean definition rather than explicitly setting a
  // postProcessor on the context so initialization follows the same code path as reading from
  // an XML config file
  GenericBeanDefinition definition = new GenericBeanDefinition();
  definition.setBeanClass(MapperScannerConfigurer.class);
  definition.getPropertyValues().add("basePackage", "org.mybatis.spring.mapper");
  applicationContext.registerBeanDefinition("mapperScanner", definition);

  setupSqlSessionFactory("sqlSessionFactory");

  // assume support for autowiring fields is added by MapperScannerConfigurer via
  // org.springframework.context.annotation.ClassPathBeanDefinitionScanner.includeAnnotationConfig
}
 
开发者ID:zyong2004,项目名称:mybatis-spring,代码行数:18,代码来源:MapperScannerConfigurerTest.java

示例14: createBeanDefinitionByIntrospection

import org.springframework.beans.factory.support.GenericBeanDefinition; //导入方法依赖的package包/类
private BeanDefinition createBeanDefinitionByIntrospection(Object object, NamedBeanMap refs,
		ConversionService conversionService) {
	validate(object);
	GenericBeanDefinition def = new GenericBeanDefinition();
	def.setBeanClass(object.getClass());
	MutablePropertyValues propertyValues = new MutablePropertyValues();
	for (PropertyDescriptor descriptor : BeanUtils.getPropertyDescriptors(object.getClass())) {
		if (descriptor.getWriteMethod() != null) {
			try {
				Object value = descriptor.getReadMethod().invoke(object, (Object[]) null);
				if (value != null) {
					if ("id".equals(descriptor.getName())) {

					} else {
						propertyValues.addPropertyValue(descriptor.getName(),
								createMetadataElementByIntrospection(value, refs, conversionService));
					}
				}
			} catch (Exception e) {
				// our contract says to ignore this property
			}
		}
	}
	def.setPropertyValues(propertyValues);
	return def;
}
 
开发者ID:geomajas,项目名称:geomajas-project-server,代码行数:27,代码来源:BeanDefinitionDtoConverterServiceImpl.java

示例15: registerWithServer

import org.springframework.beans.factory.support.GenericBeanDefinition; //导入方法依赖的package包/类
@PostConstruct
public void registerWithServer() {
	AutowireCapableBeanFactory factory = context
			.getAutowireCapableBeanFactory();
	BeanDefinitionRegistry registry = (BeanDefinitionRegistry) factory;
	GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
	beanDefinition.setBeanClass(RmiServiceExporter.class);
	beanDefinition.setAutowireCandidate(true);

	MutablePropertyValues propertyValues = new MutablePropertyValues();

	Class<?> serviceInterface = this.getClass().getInterfaces()[0];

	propertyValues.addPropertyValue("serviceInterface", serviceInterface);
	String serviceName = serviceInterface.getCanonicalName();
	propertyValues.addPropertyValue("serviceName", serviceName);
	propertyValues.addPropertyValue("service", this);
	propertyValues.addPropertyValue("registryPort", "1099");
	beanDefinition.setPropertyValues(propertyValues);

	registry.registerBeanDefinition(serviceName, beanDefinition);
	context.getBean(serviceName); // Need this else
									// NotBoundException
	getService().registerClient(getHostAddress());

}
 
开发者ID:DevOpsDistilled,项目名称:OpERP,代码行数:27,代码来源:AbstractEntityModel.java


注:本文中的org.springframework.beans.factory.support.GenericBeanDefinition.setBeanClass方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。