public static boolean parseInterfaces(Element parent, Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { String name = element.getLocalName(); // osgi:interfaces if (INTERFACES_ID.equals(name)) { // check shortcut on the parent if (parent.hasAttribute(INTERFACE)) { parserContext.getReaderContext().error( "either 'interface' attribute or <intefaces> sub-element has be specified", parent); } Set interfaces = parserContext.getDelegate().parseSetElement(element, builder.getBeanDefinition()); builder.addPropertyValue(INTERFACES_PROP, interfaces); return true; } return false; }
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { builder.addPropertyValue(PojoConst.FIELD_MICROSERVICE_NAME, element.getAttribute(PojoConst.MICROSERVICE_NAME)); String schemaId = element.getAttribute(PojoConst.SCHEMA_ID); String intf = element.getAttribute(PojoConst.INTERFACE); if (StringUtils.isEmpty(intf) && !StringUtils.isEmpty(schemaId)) { // 尝试将schemaId当作接口名使用 Class<?> consumerIntf = ClassUtils.getClassByName(null, schemaId); if (consumerIntf != null) { intf = schemaId; } } builder.addPropertyValue(PojoConst.FIELD_SCHEMA_ID, schemaId); builder.addPropertyValue(PojoConst.FIELD_INTERFACE, intf); if (StringUtils.isEmpty(schemaId) && StringUtils.isEmpty(intf)) { throw new Error("schema-id and interface can not both be empty."); } }
@Override public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) { ComposedTaskProperties properties = composedTaskProperties(); TaskParser taskParser = new TaskParser("bean-registration", properties.getGraph(), false, true); Map<String, Integer> taskSuffixMap = getTaskApps(taskParser); for (String taskName : taskSuffixMap.keySet()) { //handles the possibility that multiple instances of // task definition exist in a composed task for (int taskSuffix = 0; taskSuffixMap.get(taskName) >= taskSuffix; taskSuffix++) { BeanDefinitionBuilder builder = BeanDefinitionBuilder .rootBeanDefinition(ComposedTaskRunnerStepFactory.class); builder.addConstructorArgValue(properties); builder.addConstructorArgValue(String.format("%s_%s", taskName, taskSuffix)); builder.addPropertyValue("taskSpecificProps", getPropertiesForTask(taskName, properties)); builder.addPropertyValue("arguments", properties.getComposedTaskArguments()); registry.registerBeanDefinition(String.format("%s_%s", taskName, taskSuffix), builder.getBeanDefinition()); } } }
protected void doParse(Element element, BeanDefinitionBuilder bean) { boolean fallbackToSystemLocale = false; String[] basenames = null; if (element.hasAttribute(FALLBACK_TO_SYSTEM_LOCALE)) { fallbackToSystemLocale = Boolean.valueOf(element.getAttribute(FALLBACK_TO_SYSTEM_LOCALE)); } if (element.hasAttribute(BASENAMES)) { basenames = StringUtils.tokenizeToStringArray(element.getAttribute(BASENAMES), ","); } bean.addPropertyValue("fallbackToSystemLocale", fallbackToSystemLocale); bean.addPropertyValue("basenames", basenames); }
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { String path = element.getAttribute("path"); if (!StringUtils.hasText(path)) { parserContext.getReaderContext().error("Attribute 'path' must not be empty", element); return; } int dotIndex = path.indexOf("."); if (dotIndex == -1) { parserContext.getReaderContext().error( "Attribute 'path' must follow pattern 'beanName.propertyName'", element); return; } String beanName = path.substring(0, dotIndex); String propertyPath = path.substring(dotIndex + 1); builder.addPropertyValue("targetBeanName", beanName); builder.addPropertyValue("propertyPath", propertyPath); }
private void setDefault(Element element, BeanDefinitionBuilder builder) { String name = element.getAttribute("name"); if (StringUtils.hasText(name)) { builder.addPropertyValue("name", name); element.setAttribute("name", name); } else { throw new IllegalArgumentException("tc-template:name is not allow empty!"); } String id = element.getAttribute("id"); if (StringUtils.hasText(id)) { builder.addPropertyValue("id", id); element.setAttribute("id", Template.TC_SUFFIX + id); } else { throw new IllegalArgumentException("tc-template:id is not allow empty!"); } }
@Override protected void parseNested(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, BeanDefinition bd) { Class<?> apiClass; try { apiClass = Class.forName(helper.getAttribute(element, RedissonNamespaceParserSupport.CLASS_ATTRIBUTE)); } catch (ClassNotFoundException ex) { throw new IllegalArgumentException( "The class [" + helper.getAttribute(element, RedissonNamespaceParserSupport.CLASS_ATTRIBUTE) + "] specified in \"api-class\" attribute has not " + "found. Please check the class path.", ex); } builder.addPropertyValue("targetObject", new RuntimeBeanReference( helper.getAttribute(element, RedissonNamespaceParserSupport.LIVE_OBJECT_SERVICE_REF_ATTRIBUTE))); builder.addPropertyValue("targetMethod", "registerClass"); builder.addPropertyValue("arguments", new Object[] {apiClass}); }
private void parseNested(Element element, String eltType, ParserContext parserContext, BeanDefinitionBuilder builder, RedissonNamespaceParserSupport helper) { NodeList list = element.getElementsByTagNameNS( RedissonNamespaceParserSupport.REDISSON_NAMESPACE, eltType); if (list.getLength() == 1) { Element elt = (Element) list.item(0); if (StringUtils.hasText(referenceAttribute)) { helper.setAttribute(elt, referenceAttribute, helper.getAttribute(element, RedissonNamespaceParserSupport.ID_ATTRIBUTE)); helper.setAttribute(elt, RedissonNamespaceParserSupport.REDISSON_REF_ATTRIBUTE, helper.getAttribute(element, RedissonNamespaceParserSupport.REDISSON_REF_ATTRIBUTE)); } parserContext.getDelegate() .parseCustomElement(elt, builder.getRawBeanDefinition()); } }
@Override protected void doParse(Element element, BeanDefinitionBuilder bean) { String application = element.getAttribute("application"); String registry = element.getAttribute("registry"); String rpcPort = element.getAttribute("rpcPort"); String httpPort = element.getAttribute("httpPort"); if (StringUtils.hasText(application)) { bean.addPropertyValue("application", application); } if (StringUtils.hasText(registry)) { bean.addPropertyValue("registryAddress", registry); } if (StringUtils.hasText(rpcPort)) { bean.addPropertyValue("realityRpcPort", Integer.valueOf(rpcPort)); } if (StringUtils.hasText(httpPort)) { bean.addPropertyValue("httpPort", Integer.valueOf(httpPort)); } }
@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); } }
/** * Utility method used for maintaining backwards compatibility by converting Class objects to String (using their * class names). Used by importer and exporter parsing to set the 'interfaces' property. * * @param parsedClasses collection of parsed classes * @return a collection of converted (if necessary) metadata */ public static Set<?> convertClassesToStrings(Set<?> parsedClasses) { Set<Object> interfaces = new ManagedSet<Object>(parsedClasses.size()); for (Object clazz : parsedClasses) { if (clazz instanceof TypedStringValue || clazz instanceof String) { interfaces.add(clazz); } else { // add adapter definition for bean references (which can be classes) interfaces.add(BeanDefinitionBuilder.genericBeanDefinition(ToStringClassAdapter.class) .addConstructorArgValue(clazz).getBeanDefinition()); } } return interfaces; }
private void setDefault(Element element, BeanDefinitionBuilder builder) { String name = element.getAttribute("name"); if (StringUtils.hasText(name)) { builder.addPropertyValue("name", name); element.setAttribute("name", name); } else { throw new IllegalArgumentException("fc-template:name is not allow empty!"); } String id = element.getAttribute("id"); if (StringUtils.hasText(id)) { builder.addPropertyValue("id", id); element.setAttribute("id", Template.FC_SUFFIX + id); } else { throw new IllegalArgumentException("fc-template:id is not allow empty!"); } }
@Override public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry registry) { Map<String, Object> attributes = annotationMetadata.getAnnotationAttributes(EnableBeanContext.class.getName()); if (attributes == null) { return; } boolean lookupByType = (boolean) attributes.get("lookupByType"); // check environment if (environment.containsProperty(EnableBeanContext.LOOKUP_BY_TYPE_PROPERTY_NAME)) { lookupByType = environment.getProperty(EnableBeanContext.LOOKUP_BY_TYPE_PROPERTY_NAME, Boolean.class); } // register post processor if (!registry.containsBeanDefinition(BEAN_FACTORY_SCOPE_POST_PROCESSOR_NAME)) { BeanDefinitionBuilder postProcessorBuilder = BeanDefinitionBuilder .genericBeanDefinition(BeanFactoryScopePostProcessor.class).setDestroyMethodName("unregister") .addPropertyValue("lookupByType", lookupByType).setRole(BeanDefinition.ROLE_INFRASTRUCTURE); registry.registerBeanDefinition(BEAN_FACTORY_SCOPE_POST_PROCESSOR_NAME, postProcessorBuilder.getBeanDefinition()); } }
/** * Parse a '{@code declare-parents}' element and register the appropriate * DeclareParentsAdvisor with the BeanDefinitionRegistry encapsulated in the * supplied ParserContext. */ private AbstractBeanDefinition parseDeclareParents(Element declareParentsElement, ParserContext parserContext) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(DeclareParentsAdvisor.class); builder.addConstructorArgValue(declareParentsElement.getAttribute(IMPLEMENT_INTERFACE)); builder.addConstructorArgValue(declareParentsElement.getAttribute(TYPE_PATTERN)); String defaultImpl = declareParentsElement.getAttribute(DEFAULT_IMPL); String delegateRef = declareParentsElement.getAttribute(DELEGATE_REF); if (StringUtils.hasText(defaultImpl) && !StringUtils.hasText(delegateRef)) { builder.addConstructorArgValue(defaultImpl); } else if (StringUtils.hasText(delegateRef) && !StringUtils.hasText(defaultImpl)) { builder.addConstructorArgReference(delegateRef); } else { parserContext.getReaderContext().error( "Exactly one of the " + DEFAULT_IMPL + " or " + DELEGATE_REF + " attributes must be specified", declareParentsElement, this.parseState.snapshot()); } AbstractBeanDefinition definition = builder.getBeanDefinition(); definition.setSource(parserContext.extractSource(declareParentsElement)); parserContext.getReaderContext().registerWithGeneratedName(definition); return definition; }
private void parserFieldMixBranchs(BeanDefinitionBuilder builder, Element ele) { List<Element> childElts = DomUtils.getChildElements(ele); checkChildBranchs(childElts); Map<String, Field[]> mixInfo = new HashMap<String, Field[]>(); for (int i = 0; i < childElts.size(); i++) { Element node = childElts.get(i); // 解析branch parserBranch(mixInfo, node); } builder.addPropertyValue("isMix", true); builder.addPropertyValue("mixInfo", mixInfo); }
/** * * @param acf * @param sch * @return */ private Trigger registerSchedulerTriggerBean(DefaultListableBeanFactory acf, AbstractJob sch) { //注册JobDetail String jobDetailBeanName = sch.getJobName() + "JobDetail"; if (context.containsBean(jobDetailBeanName)) { throw new RuntimeException("duplicate jobName[" + sch.getJobName() + "] defined!!"); } BeanDefinitionBuilder beanDefBuilder = BeanDefinitionBuilder .genericBeanDefinition(MethodInvokingJobDetailFactoryBean.class); beanDefBuilder.addPropertyValue("targetObject", sch); beanDefBuilder.addPropertyValue("targetMethod", "execute"); beanDefBuilder.addPropertyValue("concurrent", false); acf.registerBeanDefinition(jobDetailBeanName, beanDefBuilder.getRawBeanDefinition()); //注册Trigger String triggerBeanName = sch.getJobName() + "Trigger"; beanDefBuilder = BeanDefinitionBuilder.genericBeanDefinition(CronTriggerFactoryBean.class); beanDefBuilder.addPropertyReference("jobDetail", jobDetailBeanName); beanDefBuilder.addPropertyValue("cronExpression", sch.getCronExpr()); beanDefBuilder.addPropertyValue("group", groupName); acf.registerBeanDefinition(triggerBeanName, beanDefBuilder.getRawBeanDefinition()); logger.info("register scheduler task [{}] ok!!", sch.getJobName()); return (Trigger) context.getBean(triggerBeanName); }
public boolean process(Element parent, Attr attribute, BeanDefinitionBuilder builder) { String name = attribute.getLocalName(); String value = attribute.getValue(); if (AVAILABILITY.equals(name)) { builder.addPropertyValue(AVAILABILITY, ReferenceParsingUtil.determineAvailability(value)); return false; } else if (COMPONENT_NAME.equals(name)) { builder.addPropertyValue(SERVICE_BEAN_NAME_PROP, value); return false; } return true; }
public static ApplicationContext buildAppContext(ApplicationContext parent, Stream<TestBean> beans, Collection<BeanFactoryPostProcessor> postProcessors) { final DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); final GenericApplicationContext applicationContext = new GenericApplicationContext(beanFactory, parent); postProcessors.forEach(applicationContext::addBeanFactoryPostProcessor); beans.forEach(entry -> { final String factoryBean = entry.getName() + "_factory"; beanFactory.registerSingleton(factoryBean, (Supplier<Object>) entry::getBean); beanFactory.registerBeanDefinition(entry.getName(), BeanDefinitionBuilder .rootBeanDefinition(entry.getBean() != null ? entry.getBean().getClass() : Object.class) .setFactoryMethodOnBean("get", factoryBean) .getBeanDefinition()); }); applicationContext.refresh(); return applicationContext; }
@Override protected void postProcess(BeanDefinitionBuilder definitionBuilder, Element element) { Object envValue = DomUtils.getChildElementValueByTagName(element, ENVIRONMENT); if (envValue != null) { // Specific environment settings defined, overriding any shared properties. definitionBuilder.addPropertyValue(JNDI_ENVIRONMENT, envValue); } else { // Check whether there is a reference to shared environment properties... String envRef = element.getAttribute(ENVIRONMENT_REF); if (StringUtils.hasLength(envRef)) { definitionBuilder.addPropertyValue(JNDI_ENVIRONMENT, new RuntimeBeanReference(envRef)); } } String lazyInit = element.getAttribute(LAZY_INIT_ATTRIBUTE); if (StringUtils.hasText(lazyInit) && !DEFAULT_VALUE.equals(lazyInit)) { definitionBuilder.setLazyInit(TRUE_VALUE.equals(lazyInit)); } }
@Override protected void registerBeans(InjectLock annotation, ResolvableType targetType, BeanDefinitionRegistry registry) { String name = LockBean.class.getName() + "-" + annotation.name() + "--" + annotation.name(); if (!registry.containsBeanDefinition(name)) { AbstractBeanDefinition def = BeanDefinitionBuilder.rootBeanDefinition(LockBean.class) .setLazyInit(true) .addPropertyValue("region", annotation.region()) .addPropertyValue("name", annotation.name()) .getBeanDefinition(); AutowireCandidateQualifier qualifier = new AutowireCandidateQualifier(annotation.annotationType()); qualifier.addMetadataAttribute(new BeanMetadataAttribute("region", annotation.region())); qualifier.addMetadataAttribute(new BeanMetadataAttribute("name", annotation.name())); def.addQualifier(qualifier); registry.registerBeanDefinition(name, def); } }
/** * 动态注册一个Bean动Spring容器中 * * @param beanName 名称 * @param beanClazz 定义bean */ public void registerBean(String beanName, Class beanClazz, Map<String, Object> propertys) { Assert.notNull(beanName); Assert.notNull(beanClazz); BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(beanClazz); if (propertys != null) { propertys.forEach((k, v) -> builder.addPropertyValue(k, v)); } builder.setScope(BeanDefinition.SCOPE_SINGLETON); registerBean(beanName, builder.getBeanDefinition()); }
@Override protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(DataSourceInitializer.class); builder.addPropertyReference("dataSource", element.getAttribute("data-source")); builder.addPropertyValue("enabled", element.getAttribute("enabled")); DatabasePopulatorConfigUtils.setDatabasePopulator(element, builder); builder.getRawBeanDefinition().setSource(parserContext.extractSource(element)); return builder.getBeanDefinition(); }
public BeanDefinition parse(Element element, ParserContext parserContext) { BeanDefinitionBuilder dwrController = BeanDefinitionBuilder.rootBeanDefinition(DwrController.class); List configurators = new ManagedList(); configurators.add(new RuntimeBeanReference(DEFAULT_SPRING_CONFIGURATOR_ID)); dwrController.addPropertyValue("configurators", configurators); String debug = element.getAttribute("debug"); if (StringUtils.hasText(debug)) { dwrController.addPropertyValue("debug", debug); } String beanName = element.getAttribute(BeanDefinitionParserDelegate.ID_ATTRIBUTE); String nameAttr = element.getAttribute(BeanDefinitionParserDelegate.NAME_ATTRIBUTE); String[] aliases = null; if (!StringUtils.hasText(beanName)) { beanName = element.getAttribute("name"); } else { String aliasName = element.getAttribute("name"); if (StringUtils.hasText(aliasName)) { aliases = StringUtils.tokenizeToStringArray(nameAttr, BeanDefinitionParserDelegate.BEAN_NAME_DELIMITERS); } } parseControllerParameters(dwrController, element); BeanDefinitionHolder holder = new BeanDefinitionHolder(dwrController.getBeanDefinition(), beanName, aliases); BeanDefinitionReaderUtils.registerBeanDefinition(holder, parserContext.getRegistry()); return dwrController.getBeanDefinition(); }
@Test public void testDoParse() throws Exception { SchemaDefParser lSchemaDefParser = new SchemaDefParser(); lSchemaDefParser.shouldGenerateId(); lSchemaDefParser.shouldParseNameAsAliases(); lSchemaDefParser.getBeanClass(null); lSchemaDefParser.doParse(Mockito.mock(Element.class), null, Mockito.mock(BeanDefinitionBuilder.class)); Assert.assertEquals(true, lSchemaDefParser.shouldGenerateId()); }
@Test public void testDoParse() throws Exception { ReferenceDefParser lReferenceDefParser = new ReferenceDefParser(); Element element = Mockito.mock(Element.class); Mockito.when(element.getAttribute(PojoConst.SCHEMA_ID)).thenReturn("abc"); lReferenceDefParser.doParse(element, null, Mockito.mock(BeanDefinitionBuilder.class)); Assert.assertEquals(PojoReferenceMeta.class, lReferenceDefParser.getBeanClass(null)); }
@Override public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) { MultiValueMap<String, Object> attributes = metadata.getAllAnnotationAttributes(EnableMessageSource.class.getName(), false); boolean fallbackToSystemLocale = (boolean) (attributes != null ? attributes.getFirst("fallbackToSystemLocale") : false); String[] basenames = (String[]) (attributes != null ? attributes.getFirst("basenames") : null); BeanDefinitionBuilder bean = BeanDefinitionBuilder.genericBeanDefinition(ConfigMessageSourceConfigurer.class); bean.addPropertyValue("fallbackToSystemLocale", fallbackToSystemLocale); if (basenames != null && basenames.length > 0) { bean.addPropertyValue("basenames", basenames); } registry.registerBeanDefinition(ConfigMessageSourceConfigurer.class.getName(), bean.getBeanDefinition()); }
/** * Generic attribute callback. Will parse the given callback array, w/o any standard callback. * * @param element XML element * @param builder current bean definition builder * @param callbacks array of callbacks (can be null/empty) */ public static void parseAttributes(Element element, BeanDefinitionBuilder builder, AttributeCallback[] callbacks) { NamedNodeMap attributes = element.getAttributes(); for (int x = 0; x < attributes.getLength(); x++) { Attr attr = (Attr) attributes.item(x); boolean shouldContinue = true; if (!ObjectUtils.isEmpty(callbacks)) for (int i = 0; i < callbacks.length && shouldContinue; i++) { AttributeCallback callback = callbacks[i]; shouldContinue = callback.process(element, attr, builder); } } }
private void parserFieldMixCommonEnd(BeanDefinitionBuilder builder, List<Element> eles) { if (!CollectionUtils.isEmpty(eles)) { Field[] endFields = new Field[eles.size()]; for (int i = 0; i < eles.size(); i++) { endFields[i] = parserField(eles.get(i),false); } builder.addPropertyValue("endFields", endFields); } }
private void dealId(Element element, BeanDefinitionBuilder builder) { String id = element.getAttribute("id"); if (!StringUtils.hasText(id)) { // builder.addPropertyValue("id", defaultId); element.setAttribute("id", defaultId); } else { // builder.addPropertyValue("id", id); } }
@Override protected void doParse(Element element, BeanDefinitionBuilder builder) { String key = element.getAttribute("key"); builder.addPropertyValue("key", key); setDefault(element,builder); String className = element.getAttribute("class"); if (StringUtils.hasText(className)) { builder.getBeanDefinition().setBeanClassName(className); } List<Element> childElts = DomUtils.getChildElements(element); // 解析fields if (CollectionUtils.isEmpty(childElts)) { throw new IllegalArgumentException("cjava:header node must contain fields"); } Field[] values = new Field[childElts.size()]; for (int i = 0; i < childElts.size(); i++) { Element node = childElts.get(i); // 解析 values[i] = parserField(node,true); } builder.addPropertyValue("fields", values); }
private void registerConverters(BeanDefinitionRegistry registry, List<Class<?>> types) { // Register ConfigConverter by CustomConverterConfigurer String name = ConfigBeanConverterConfigurer.class.getName() + "." + EnableConfigService.class.getSimpleName(); // converters List<ConfigBeanConverter> converters = instantiateConverters(types); BeanDefinitionBuilder builder = BeanDefinitionBuilder .genericBeanDefinition(ConfigBeanConverterConfigurer.class); builder.addPropertyValue("converters", converters); AbstractBeanDefinition beanDefinition = builder.getBeanDefinition(); registry.registerBeanDefinition(name, beanDefinition); }
/** * 注册Hermes * * @param registry spring bean注册器 */ private void registerHermes(BeanDefinitionRegistry registry) throws InstantiationException, IllegalAccessException { String[] zones = this.environment.getProperty("hermes.center-zone").split(","); List<Center> centers = new ArrayList<>(zones.length); String name = this.environment.getProperty("spring.application.name"); for (String zone : zones) { Center center = new Center(zone); center.register(name, this.environment.getProperty("server.port")); centers.add(center); } // 扫描所有类,forPackage放空字符串表示扫描主包 Reflections reflections = new Reflections(new ConfigurationBuilder() .setUrls(ClasspathHelper.forPackage("")) .setExpandSuperTypes(false) ); // 注册spring上下文帮助 BeanDefinitionBuilder bdb = BeanDefinitionBuilder.rootBeanDefinition(ApplicationContextHelper.class); registry.registerBeanDefinition("applicationContextHelper", bdb.getBeanDefinition()); // 注册注册中心bean bdb = BeanDefinitionBuilder.rootBeanDefinition(Centers.class) .addPropertyValue("centers", centers); registry.registerBeanDefinition(Constant.CENTERS_BEAN_NAME, bdb.getBeanDefinition()); // 注册监听 Set<String> urlMappings = new HashSet<>(1); urlMappings.add("/hermes"); bdb = BeanDefinitionBuilder.rootBeanDefinition(ServletRegistrationBean.class) .addPropertyValue("servlet", new HermesServlet(this.getMethodMap(reflections))) .addPropertyValue("urlMappings", urlMappings); registry.registerBeanDefinition("hermesServlet", bdb.getBeanDefinition()); // 注册client registerClient(reflections, registry); }
@Override protected void doParse(Element element, BeanDefinitionBuilder builder) { super.doParse(element, builder); builder.addPropertyValue("ignoreUnresolvablePlaceholders", Boolean.valueOf(element.getAttribute("ignore-unresolvable"))); String systemPropertiesModeName = element.getAttribute(SYSTEM_PROPERTIES_MODE_ATTRIB); if (StringUtils.hasLength(systemPropertiesModeName) && !systemPropertiesModeName.equals(SYSTEM_PROPERTIES_MODE_DEFAULT)) { builder.addPropertyValue("systemPropertiesModeName", "SYSTEM_PROPERTIES_MODE_"+systemPropertiesModeName); } }
protected void parseAttributes(Element element, BeanDefinitionBuilder builder, AttributeCallback[] callbacks, OsgiDefaultsDefinition defaults) { // add timeout callback TimeoutAttributeCallback timeoutCallback = new TimeoutAttributeCallback(); super.parseAttributes(element, builder, ParserUtils.mergeCallbacks(callbacks, new AttributeCallback[] { timeoutCallback }), defaults); // look for defaults if (!timeoutCallback.isTimeoutSpecified) { applyDefaultTimeout(builder, defaults); } }
@Override public void decorate(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, RedissonNamespaceParserSupport helper) { Assert.state(element.hasAttribute(DESTINATION_QUEUE_REF), "Illegal state. property \"" + DESTINATION_QUEUE_REF + "\" is required in the \"" + helper.getName(element) + "\" element."); helper.addConstructorArgs(new RuntimeBeanReference( helper.getAttribute(element, DESTINATION_QUEUE_REF)), RQueue.class, builder); }
@Override protected void applyDefaults(ParserContext parserContext, OsgiDefaultsDefinition defaults, BeanDefinitionBuilder builder) { super.applyDefaults(parserContext, defaults, builder); if (defaults instanceof BlueprintDefaultsDefinition) { BlueprintDefaultsDefinition defs = (BlueprintDefaultsDefinition) defaults; if (defs.getDefaultInitialization()) { builder.setLazyInit(defs.getDefaultInitialization()); } } }
@Override protected void doParse(Element element, BeanDefinitionBuilder builder) { // 是否有class if (element.hasAttribute("class") && StringUtils.hasText(element.getAttribute("class"))) { // 重新赋值 checkClass(element.getAttribute("class")); builder.getRawBeanDefinition().setBeanClassName(element.getAttribute("class")); } else { builder.getRawBeanDefinition().setBeanClassName(defaultClass); } dealId(element,builder); }
@Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { final BeanDefinitionRegistry definitionRegistry = (BeanDefinitionRegistry) beanFactory; definitionRegistry.registerBeanDefinition("service", BeanDefinitionBuilder .rootBeanDefinition(Service.class) .setFactoryMethodOnBean("createService", "serviceFactory") .getBeanDefinition()); }
private void parseAddressTypes(Element element, String addressType, BeanDefinitionBuilder redissonDef, ParserContext parserContext) { BeanComponentDefinition invoker = helper.invoker(element, parserContext.getContainingComponent().getName(), "add" + StringUtils.capitalize(addressType), new String[]{element.getAttribute("value")}, parserContext); String id = invoker.getName(); redissonDef.addDependsOn(id); }
protected void doParse(Element element, BeanDefinitionBuilder bean) { String name = element.getAttribute("name"); bean.addConstructorArgValue(name); String parents = element.getAttribute("parentNames"); List<String> parentList = null == parents ? null : Splitter.on(',').trimResults().omitEmptyStrings().splitToList(parents); bean.addConstructorArgValue(null == parentList ? Collections.emptyList() : parentList); }