Java Code Examples for org.springframework.beans.factory.config.BeanDefinition#setFactoryMethodName()
The following examples show how to use
org.springframework.beans.factory.config.BeanDefinition#setFactoryMethodName() .
These examples are extracted from open source projects.
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 Project: redisson File: RedissonGenericObjectDefinitionParser.java License: Apache License 2.0 | 6 votes |
@Override protected void parseNested(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, BeanDefinition bd) { bd.setFactoryBeanName(element.getAttribute( RedissonNamespaceParserSupport.REDISSON_REF_ATTRIBUTE)); String typeName = Conventions.attributeNameToPropertyName(element.getLocalName()); bd.setFactoryMethodName("get" + StringUtils.capitalize(typeName)); helper.addConstructorArgs(element, KEY_ATTRIBUTE, String.class, builder); helper.addConstructorArgs(element, TOPIC_ATTRIBUTE, String.class, builder); helper.addConstructorArgs(element, PATTERN_ATTRIBUTE, String.class, builder); helper.addConstructorArgs(element, SERVICE_ATTRIBUTE, String.class, builder); helper.addConstructorArgs(element, CODEC_REF_ATTRIBUTE, Codec.class, builder); if (RDestroyable.class.isAssignableFrom(getBeanClass(element))) { ((AbstractBeanDefinition) bd).setDestroyMethodName("destroy"); } }
Example 2
Source Project: das File: DasTransactionalEnabler.java License: Apache License 2.0 | 5 votes |
private void replaceBeanDefinition() { for(String beanName: getBeanDefinitionNames()) { BeanDefinition beanDef = getBeanDefinition(beanName); String beanClassName = beanDef.getBeanClassName(); if(beanClassName == null || beanClassName.equals(BEAN_FACTORY_NAME) || isSpringSmartClassLoader(beanDef)) { continue; } Class beanClass; try { beanClass = Class.forName(beanDef.getBeanClassName()); } catch (ClassNotFoundException e) { throw new BeanDefinitionValidationException("Cannot validate bean: " + beanName, e); } boolean annotated = false; for (Method method : beanClass.getMethods()) { if(isTransactionAnnotated(method)) { annotated = true; break; } } if(!annotated) { continue; } beanDef.setBeanClassName(BEAN_FACTORY_NAME); beanDef.setFactoryMethodName(FACTORY_METHOD_NAME); ConstructorArgumentValues cav = beanDef.getConstructorArgumentValues(); if(cav.getArgumentCount() != 0) { throw new BeanDefinitionValidationException("The transactional bean can only be instantiated with default constructor."); } cav.addGenericArgumentValue(beanClass.getName()); } }
Example 3
Source Project: spring-analysis-note File: ScheduledAnnotationBeanPostProcessorTests.java License: MIT License | 5 votes |
@Test public void severalFixedRatesAgainstNestedCglibProxy() { BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class); BeanDefinition targetDefinition = new RootBeanDefinition(SeveralFixedRatesWithRepeatedScheduledAnnotationTestBean.class); targetDefinition.setFactoryMethodName("nestedProxy"); severalFixedRates(context, processorDefinition, targetDefinition); }
Example 4
Source Project: java-technology-stack File: ScheduledAnnotationBeanPostProcessorTests.java License: MIT License | 5 votes |
@Test public void severalFixedRatesAgainstNestedCglibProxy() { BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class); BeanDefinition targetDefinition = new RootBeanDefinition(SeveralFixedRatesWithRepeatedScheduledAnnotationTestBean.class); targetDefinition.setFactoryMethodName("nestedProxy"); severalFixedRates(context, processorDefinition, targetDefinition); }
Example 5
Source Project: redisson File: RedissonReadAndWriteLockDefinitionParser.java License: Apache License 2.0 | 5 votes |
@Override protected void parseNested(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, BeanDefinition bd) { bd.setFactoryBeanName(element.getAttribute( RedissonNamespaceParserSupport.READ_WRITE_LOCK_REF_ATTRIBUTE)); String typeName = Conventions.attributeNameToPropertyName(element.getLocalName()); bd.setFactoryMethodName(typeName); }
Example 6
Source Project: syncope File: DomainTransactionInterceptorInjector.java License: Apache License 2.0 | 5 votes |
@Override public void postProcessBeanFactory(final ConfigurableListableBeanFactory beanFactory) throws BeansException { for (String name : beanFactory.getBeanNamesForType(TransactionInterceptor.class, false, false)) { BeanDefinition bd = beanFactory.getBeanDefinition(name); bd.setBeanClassName(DomainTransactionInterceptor.class.getName()); bd.setFactoryBeanName(null); bd.setFactoryMethodName(null); } }
Example 7
Source Project: dal File: DalTransactionalEnabler.java License: Apache License 2.0 | 4 votes |
private void replaceBeanDefinition() { for (String beanName : getBeanDefinitionNames()) { BeanDefinition beanDef = getBeanDefinition(beanName); String beanClassName = beanDef.getBeanClassName(); if (beanClassName == null || beanClassName.equals(BEAN_FACTORY_NAME)) continue; Class beanClass; try { beanClass = Class.forName(beanDef.getBeanClassName()); } catch (ClassNotFoundException e) { throw new BeanDefinitionValidationException("Cannot validate bean: " + beanName, e); } boolean annotated = false; List<Method> methods = new ArrayList<>(); ReflectUtils.addAllMethods(beanClass, methods); List<Method> unsupportedMethods = new ArrayList<>(); for (int i = 0; i < methods.size(); i++) { Method currentMethod = methods.get(i); if (isTransactionAnnotated(currentMethod)) { if (Modifier.isFinal(currentMethod.getModifiers()) || Modifier.isStatic(currentMethod.getModifiers()) || Modifier.isPrivate(currentMethod.getModifiers())) unsupportedMethods.add(currentMethod); annotated = true; } } if (!unsupportedMethods.isEmpty()){ StringBuilder errMsg=new StringBuilder(); errMsg.append(String.format("The Methods below are not supported in dal transaction due to private, final or static modifier, please use public,protected or default modifier instead:")); errMsg.append("\n"); int index=1; for (Method method : unsupportedMethods) { errMsg.append(String.format("%d. %s", index, method.toString())); errMsg.append("\n"); index++; } throw new DalRuntimeException(errMsg.toString()); } if (!annotated) continue; beanDef.setBeanClassName(BEAN_FACTORY_NAME); beanDef.setFactoryMethodName(FACTORY_METHOD_NAME); ConstructorArgumentValues cav = beanDef.getConstructorArgumentValues(); if (cav.getArgumentCount() != 0) throw new BeanDefinitionValidationException("The transactional bean can only be instantiated with default constructor."); cav.addGenericArgumentValue(beanClass.getName()); } }