Java Code Examples for org.springframework.beans.factory.support.BeanDefinitionBuilder#getRawBeanDefinition()
The following examples show how to use
org.springframework.beans.factory.support.BeanDefinitionBuilder#getRawBeanDefinition() .
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: ModuleClassLoader.java From TrackRay with GNU General Public License v3.0 | 6 votes |
/** * 方法描述 初始化spring bean * @method initBean */ public void initBean(){ for (Map.Entry<String, Class> entry : cacheClassMap.entrySet()) { String className = entry.getKey(); Class<?> cla = entry.getValue(); if(isSpringBeanClass(cla)){ BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(cla); BeanDefinition beanDefinition = beanDefinitionBuilder.getRawBeanDefinition(); //设置当前bean定义对象是单利的 beanDefinition.setScope("singleton"); //将变量首字母置小写 String beanName = StringUtils.uncapitalize(className); beanName = beanName.substring(beanName.lastIndexOf(".")+1); beanName = StringUtils.uncapitalize(beanName); registeredBean.add(beanName); System.out.println("注册bean:"+beanName); } } }
Example 2
Source File: DatasourceBeanDefinitionRegistry.java From sofa-tracer with Apache License 2.0 | 6 votes |
@Override public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException { BeanDefinitionBuilder definitionBuilder = BeanDefinitionBuilder .genericBeanDefinition(HikariDataSource.class); AbstractBeanDefinition beanDefinition = definitionBuilder.getRawBeanDefinition(); beanDefinition.setDestroyMethodName("close"); beanDefinition.setPrimary(false); definitionBuilder.addPropertyValue("driverClassName", "org.h2.Driver"); definitionBuilder .addPropertyValue( "jdbcUrl", "jdbc:mysql://1.1.1.1:3306/xxx?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull"); definitionBuilder.addPropertyValue("username", "sofa"); definitionBuilder.addPropertyValue("password", "123456"); registry.registerBeanDefinition("manualDataSource", definitionBuilder.getRawBeanDefinition()); }
Example 3
Source File: RedissonDefinitionParser.java From redisson with Apache License 2.0 | 6 votes |
private void parseConfigTypes(Element element, String configType, BeanDefinitionBuilder redissonDef, ParserContext parserContext) { BeanDefinitionBuilder builder = helper.createBeanDefinitionBuilder(element, parserContext, null); //Use factory method on the Config bean AbstractBeanDefinition bd = builder.getRawBeanDefinition(); bd.setFactoryMethodName("use" + StringUtils.capitalize(configType)); bd.setFactoryBeanName(parserContext.getContainingComponent().getName()); String id = parserContext.getReaderContext().generateBeanName(bd); helper.registerBeanDefinition(builder, id, helper.parseAliase(element), parserContext); helper.parseAttributes(element, parserContext, builder); redissonDef.addDependsOn(id); parseChildElements(element, id, null, redissonDef, parserContext); parserContext.getDelegate().parseQualifierElements(element, bd); }
Example 4
Source File: AbstractRedissonNamespaceDefinitionParser.java From redisson with Apache License 2.0 | 6 votes |
@Override protected final void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { Assert.state(helper.isRedissonNS(element), "Illegal state. " + this.getClass().getName() + " can only parse " + RedissonNamespaceParserSupport.REDISSON_NAMESPACE + " namespace elements"); Assert.state(element.hasAttribute(parentRefAttribute), "Illegal state. property \"" + parentRefAttribute + "\" is required in the \"" + helper.getName(element) + "\" element."); helper.populateIdAttribute(element, builder, parserContext); AbstractBeanDefinition bd = builder.getRawBeanDefinition(); parseNested(element, parserContext, builder, bd); decorator.decorate(element, parserContext, builder, helper); parserContext.getDelegate().parseQualifierElements(element, bd); if (parserContext.isNested()) { helper.registerBeanDefinition(builder, element, parserContext); } }
Example 5
Source File: SmartSwaggerDynamicGroupConfig.java From smart-admin with MIT License | 5 votes |
@Override public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException { this.groupBuild(); for (Map.Entry<String, List<String>> entry : groupMap.entrySet()) { String group = entry.getKey(); BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(Docket.class, this :: baseDocket); BeanDefinition beanDefinition = builder.getRawBeanDefinition(); registry.registerBeanDefinition(group + "Api", beanDefinition); } }
Example 6
Source File: WebContext.java From Milkomeda with MIT License | 5 votes |
/** * 构建BeanDefinition * @param clazz bean类 * @param args 构造参数 * @return BeanDefinition */ public static BeanDefinition build(Class<?> clazz, Object... args) { BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(clazz); for (Object arg : args) { beanDefinitionBuilder.addConstructorArgValue(arg); } return beanDefinitionBuilder.getRawBeanDefinition(); }
Example 7
Source File: ExtensionLoader.java From spi-imp with BSD 3-Clause "New" or "Revised" License | 5 votes |
private Object parseClassToSpringBean(String name, Class<?> obj) { String beanName = obj.getSimpleName().concat(name); BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(obj); GenericBeanDefinition definition = (GenericBeanDefinition) builder.getRawBeanDefinition(); definition.setAutowireMode(GenericBeanDefinition.AUTOWIRE_BY_NAME); getRegistry().registerBeanDefinition(beanName, definition); return context.getBean(beanName); }
Example 8
Source File: CustomBeanDefinitionRegistryPostProcessor.java From blog with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException { System.out.println("postProcessBeanDefinitionRegistry"); Class<?> cls = PersonBean.class; BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(cls); GenericBeanDefinition definition = (GenericBeanDefinition) builder.getRawBeanDefinition(); definition.setAutowireMode(GenericBeanDefinition.AUTOWIRE_BY_TYPE); definition.getPropertyValues().add("name", "pepsi02"); // 注册bean名,一般为类名首字母小写 registry.registerBeanDefinition("person2", definition); BeanDefinition beanDefinition = registry.getBeanDefinition("person1"); System.out.println("postProcessBeanDefinitionRegistry修改属性name值"); beanDefinition.getPropertyValues().add("name", "tom"); }
Example 9
Source File: SentinelBeanPostProcessor.java From spring-cloud-alibaba with Apache License 2.0 | 5 votes |
private void registerBean(String interceptorBeanName, SentinelRestTemplate sentinelRestTemplate, RestTemplate restTemplate) { // register SentinelProtectInterceptor bean DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) applicationContext .getAutowireCapableBeanFactory(); BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder .genericBeanDefinition(SentinelProtectInterceptor.class); beanDefinitionBuilder.addConstructorArgValue(sentinelRestTemplate); beanDefinitionBuilder.addConstructorArgValue(restTemplate); BeanDefinition interceptorBeanDefinition = beanDefinitionBuilder .getRawBeanDefinition(); beanFactory.registerBeanDefinition(interceptorBeanName, interceptorBeanDefinition); }
Example 10
Source File: AbstractDataBaseBean.java From spring-boot-starter-dao with Apache License 2.0 | 5 votes |
protected final AbstractBeanDefinition createDataSource(MybatisNodeProperties druidNodeConfig, DruidProperties defaultConfig, String dataSourceName) { Assert.notNull(druidNodeConfig, String .format("DynamicDataSource 未初始化 ,dataSourceName=%s,失败原因: 配置参数为空,你的配置可能存在问题!", dataSourceName + "")); BeanDefinitionBuilder definitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(DynamicDataSource.class); definitionBuilder.addConstructorArgValue(druidNodeConfig); definitionBuilder.addConstructorArgValue(defaultConfig); definitionBuilder.addConstructorArgValue(dataSourceName); definitionBuilder.setInitMethodName("init"); definitionBuilder.setDestroyMethodName("close"); return definitionBuilder.getRawBeanDefinition(); }
Example 11
Source File: CustomBeanDefinitionParser.java From jdal with Apache License 2.0 | 5 votes |
/** * Parse bean like a real bean definition. * @param ele element * @param parserContext parserContext * @param builder builder */ protected void parseBeanDefinition(Element ele, ParserContext parserContext, BeanDefinitionBuilder builder) { BeanDefinitionParserDelegate delegate = parserContext.getDelegate(); AbstractBeanDefinition bd = builder.getRawBeanDefinition(); XmlReaderContext reader = parserContext.getReaderContext(); try { delegate.parseBeanDefinitionAttributes(ele, beanName, null , bd); bd.setDescription(DomUtils.getChildElementValueByTagName(ele, "description")); delegate.parseMetaElements(ele, bd); delegate.parseLookupOverrideSubElements(ele, bd.getMethodOverrides()); delegate.parseReplacedMethodSubElements(ele, bd.getMethodOverrides()); delegate.parseConstructorArgElements(ele, bd); delegate.parsePropertyElements(ele, bd); delegate.parseQualifierElements(ele, bd); } catch (NoClassDefFoundError err) { reader.error("Class that bean class [" + this.beanClass + "] depends on not found", ele, err); } catch (Throwable ex) { reader.error("Unexpected failure during bean definition parsing", ele, ex); } }
Example 12
Source File: ReyClientBeanRegistrar.java From x7 with Apache License 2.0 | 4 votes |
@Override public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry registry) { String startClassName = annotationMetadata.getClassName(); String basePackage = startClassName.substring(0, startClassName.lastIndexOf(".")); Set<Class<?>> set = ClassFileReader.getClasses(basePackage); Map<String, Object> attributes = annotationMetadata.getAnnotationAttributes(EnableReyClient.class.getName()); Object obj = attributes.get("basePackages"); if (obj != null){ String[] strs = (String[]) obj; for (String str : strs){ Set<Class<?>> set1 = ClassFileReader.getClasses(str); set.addAll(set1); } } List<String> beanNameList = new ArrayList<>(); for (Class clz : set) { ReyClient annotation = (ReyClient)clz.getAnnotation(ReyClient.class); if (annotation == null) continue; ClientParser.parse(clz,environment); String beanName = clz.getName(); beanNameList.add(beanName); String backend = annotation.circuitBreaker(); if (backend.equals(" ")){ backend = null; } boolean retry = annotation.retry(); if (!registry.containsBeanDefinition(beanName)) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(clz); GenericBeanDefinition definition = (GenericBeanDefinition) builder.getRawBeanDefinition(); definition.getPropertyValues().add("objectType", clz); definition.getPropertyValues().add("backend",backend); definition.getPropertyValues().add("retry",retry); definition.setBeanClass(HttpClientProxy.class); definition.setAutowireMode(GenericBeanDefinition.AUTOWIRE_BY_TYPE); registry.registerBeanDefinition(beanName, definition); } } }
Example 13
Source File: AbstractDataBaseBean.java From spring-boot-starter-dao with Apache License 2.0 | 4 votes |
protected final AbstractBeanDefinition createTransactionManager(String dataSourceName) { BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(DataSourceTransactionManager.class); bdb.addConstructorArgReference(dataSourceName); return bdb.getRawBeanDefinition(); }
Example 14
Source File: AbstractDataBaseBean.java From spring-boot-starter-dao with Apache License 2.0 | 4 votes |
protected final AbstractBeanDefinition createJdbcTemplate(String dataSourceName) { BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(JdbcTemplate.class); bdb.addConstructorArgReference(dataSourceName); return bdb.getRawBeanDefinition(); }