本文整理汇总了Java中org.springframework.beans.factory.support.GenericBeanDefinition类的典型用法代码示例。如果您正苦于以下问题:Java GenericBeanDefinition类的具体用法?Java GenericBeanDefinition怎么用?Java GenericBeanDefinition使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GenericBeanDefinition类属于org.springframework.beans.factory.support包,在下文中一共展示了GenericBeanDefinition类的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;
}
示例2: testOverallMetadata
import org.springframework.beans.factory.support.GenericBeanDefinition; //导入依赖的package包/类
public void testOverallMetadata() throws Exception {
BeanDefinition def = new GenericBeanDefinition();
assertEquals(new SimpleComponentMetadata(null, def), new SimpleComponentMetadata("foo", def));
Collection<ComponentMetadata> metadata = blueprintContainer.getMetadata(ComponentMetadata.class);
for (ComponentMetadata componentMetadata : metadata) {
if (componentMetadata instanceof ServiceReferenceMetadata) {
System.out.println(componentMetadata.getId());
}
}
// 1+1+3+4+4+5+3+1=22
assertEquals(22, metadata.size());
System.out.println(blueprintContainer.getComponentIds());
}
示例3: createBeanDefinition
import org.springframework.beans.factory.support.GenericBeanDefinition; //导入依赖的package包/类
protected AbstractBeanDefinition createBeanDefinition() {
AbstractBeanDefinition bd = new GenericBeanDefinition();
bd.setBeanClass(this.clazz);
if (!CollectionUtils.isEmpty(this.constructorArgs)) {
ConstructorArgumentValues cav = new ConstructorArgumentValues();
for (Object constructorArg : this.constructorArgs) {
cav.addGenericArgumentValue(constructorArg);
}
bd.setConstructorArgumentValues(cav);
}
if (this.parentName != null) {
bd.setParentName(this.parentName);
}
this.definitionWrapper = new BeanWrapperImpl(bd);
return bd;
}
示例4: 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);
}
示例5: 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);
}
}
示例6: doScan
import org.springframework.beans.factory.support.GenericBeanDefinition; //导入依赖的package包/类
/**
* Calls the parent search that will search and register all the candidates.
* Then the registered objects are post processed to set them as
* MapperFactoryBeans
*/
@Override
public Set<BeanDefinitionHolder> doScan(String... basePackages) {
Set<BeanDefinitionHolder> beanDefinitions = super.doScan(basePackages);
if (beanDefinitions.isEmpty()) {
log.warn("No WestCacheable was found in '{}' package. " +
"Please check your configuration.",
Arrays.toString(basePackages));
return beanDefinitions;
}
for (val holder : beanDefinitions) {
val definition = (GenericBeanDefinition) holder.getBeanDefinition();
log.debug("Creating WestCacheableFactoryBean with name '{}' and '{}'",
holder.getBeanName(), definition.getBeanClassName());
// the mapper interface is the original class of the bean
// but, the actual class of the bean is MapperFactoryBean
definition.getPropertyValues().add("targetClass", definition.getBeanClassName());
definition.setBeanClass(WestCacheableFactoryBean.class);
}
return beanDefinitions;
}
示例7: 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());
}
示例8: 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;
}
示例9: 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 {
assertThat(ConfigurationPropertiesWithFactoryBean.factoryBeanInit)
.as("Init too early").isFalse();
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();
assertThat(ConfigurationPropertiesWithFactoryBean.factoryBeanInit).as("No init")
.isTrue();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:21,代码来源:ConfigurationPropertiesBindingPostProcessorTests.java
示例10: registerBeanDefinitions
import org.springframework.beans.factory.support.GenericBeanDefinition; //导入依赖的package包/类
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
Map<Object, Object> targetDataSources = new HashMap<Object, Object>();
// 将主数据源添加到更多数据源中
targetDataSources.put("dataSource", defaultDataSource);
DynamicDataSourceContextHolder.dataSourceIds.add("dataSource");
// 添加更多数据源
targetDataSources.putAll(customDataSources);
for (String key : customDataSources.keySet()) {
DynamicDataSourceContextHolder.dataSourceIds.add(key);
}
// 创建DynamicDataSource
GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
beanDefinition.setBeanClass(DynamicDataSource.class);
beanDefinition.setSynthetic(true);
MutablePropertyValues mpv = beanDefinition.getPropertyValues();
mpv.addPropertyValue("defaultTargetDataSource", defaultDataSource);
mpv.addPropertyValue("targetDataSources", targetDataSources);
registry.registerBeanDefinition("dataSource", beanDefinition);
logger.info("Dynamic DataSource Registry");
}
示例11: getStoreCandidates
import org.springframework.beans.factory.support.GenericBeanDefinition; //导入依赖的package包/类
public static Set<GenericBeanDefinition> getStoreCandidates(ResourceLoader loader, String[] basePackages) {
StoreCandidateComponentProvider scanner = new StoreCandidateComponentProvider(false);
//scanner.setConsiderNestedRepositoryInterfaces(shouldConsiderNestedRepositories());
scanner.setResourceLoader(loader);
//scanner.setEnvironment(environment);
/*for (TypeFilter filter : getExcludeFilters()) {
scanner.addExcludeFilter(filter);
}*/
Set<GenericBeanDefinition> result = new HashSet<>();
for (String basePackage : basePackages) {
Set<BeanDefinition> candidates = scanner.findCandidateComponents(basePackage);
for (BeanDefinition candidate : candidates)
result.add((GenericBeanDefinition)candidate);
}
return result;
}
示例12: 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);
}
示例13: registerDataSources
import org.springframework.beans.factory.support.GenericBeanDefinition; //导入依赖的package包/类
/**
* 将数据源注入到Spring中
*
* @param registry
* @param dataSourcesMapping
*/
private void registerDataSources(BeanDefinitionRegistry registry,
Map<String, Map<DataSourceType, DataSource>> dataSourcesMapping) {
for (Map.Entry<String, Map<DataSourceType, DataSource>> entry : dataSourcesMapping.entrySet()) {
final String name = entry.getKey();
for (Map.Entry<DataSourceType, DataSource> subEntry : entry.getValue().entrySet()) {
GenericBeanDefinition dataSourceBeanDefinition = new GenericBeanDefinition();
dataSourceBeanDefinition.setBeanClass(DataSourceFactoryBean.class);
ConstructorArgumentValues constructorArgumentValues = new ConstructorArgumentValues();
constructorArgumentValues.addIndexedArgumentValue(0, subEntry.getValue());
dataSourceBeanDefinition.setConstructorArgumentValues(constructorArgumentValues);
String beanName = name + Character.toUpperCase(subEntry.getKey().name().charAt(0))
+ subEntry.getKey().name().substring(1) + "DataSource";
registry.registerBeanDefinition(beanName, dataSourceBeanDefinition);
}
}
}
示例14: createBeanDefinition
import org.springframework.beans.factory.support.GenericBeanDefinition; //导入依赖的package包/类
private static BeanDefinition createBeanDefinition(ComponentDefinition componentDefinition) {
GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
beanDefinition.setBeanClassName(componentDefinition.getComponentClass());
beanDefinition.setScope(getScope(componentDefinition.getScope()));
beanDefinition.setAutowireCandidate(true);
beanDefinition.setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_BY_NAME);
beanDefinition.setDependsOn(componentDefinition.getDependsOn());
beanDefinition.setLazyInit(componentDefinition.isLazyInit());
ConstructorArgumentValues constructorArgumentValues = new ConstructorArgumentValues();
for (Object value : componentDefinition.getConstructorArguments()) {
constructorArgumentValues.addIndexedArgumentValue(constructorArgumentValues.getArgumentCount(), value);
}
beanDefinition.setConstructorArgumentValues(constructorArgumentValues);
MutablePropertyValues propertyValues = new MutablePropertyValues();
for (PropertyValue propertyValue : componentDefinition.getPropertyValues()) {
propertyValues.add(propertyValue.getName(), propertyValue.getValue());
}
beanDefinition.setPropertyValues(propertyValues);
return beanDefinition;
}
示例15: 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");
}