org.springframework.beans.factory.support.GenericBeanDefinition Java Examples
The following examples show how to use
org.springframework.beans.factory.support.GenericBeanDefinition.
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: GroovyBeanDefinitionWrapper.java From spring4-understanding with Apache License 2.0 | 6 votes |
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; }
Example #2
Source File: BeanDefinitionDtoConverterServiceImpl.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
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; }
Example #3
Source File: BeanDefinitionDtoConverterServiceImpl.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
/** * Convert from an internal Spring bean definition to a DTO. * * @param beanDefinition The internal Spring bean definition. * @return Returns a DTO representation. */ public BeanDefinitionInfo toDto(BeanDefinition beanDefinition) { if (beanDefinition instanceof GenericBeanDefinition) { GenericBeanDefinitionInfo info = new GenericBeanDefinitionInfo(); info.setClassName(beanDefinition.getBeanClassName()); if (beanDefinition.getPropertyValues() != null) { Map<String, BeanMetadataElementInfo> propertyValues = new HashMap<String, BeanMetadataElementInfo>(); for (PropertyValue value : beanDefinition.getPropertyValues().getPropertyValueList()) { Object obj = value.getValue(); if (obj instanceof BeanMetadataElement) { propertyValues.put(value.getName(), toDto((BeanMetadataElement) obj)); } else { throw new IllegalArgumentException("Type " + obj.getClass().getName() + " is not a BeanMetadataElement for property: " + value.getName()); } } info.setPropertyValues(propertyValues); } return info; } else { throw new IllegalArgumentException("Conversion to DTO of " + beanDefinition.getClass().getName() + " not implemented"); } }
Example #4
Source File: QualifierAnnotationTests.java From spring-analysis-note with MIT License | 6 votes |
@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()); }
Example #5
Source File: GroovyBeanDefinitionWrapper.java From blog_demos with Apache License 2.0 | 6 votes |
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; }
Example #6
Source File: MulCommonBaseServiceParser.java From zxl with Apache License 2.0 | 6 votes |
private BeanDefinition buildSessionFactoryBeanDefinition(Element element, String name, BeanDefinitionParserDelegate beanDefinitionParserDelegate, BeanDefinitionRegistry beanDefinitionRegistry) { AbstractBeanDefinition beanDefinition = new GenericBeanDefinition(); beanDefinition.setAttribute(ID_ATTRIBUTE, name + SESSION_FACTORY_SUFFIX); beanDefinition.setBeanClass(LocalSessionFactoryBean.class); beanDefinition.setParentName(SESSION_FACTORY_PARENT_BEAN_NAME); MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("dataSource", new RuntimeBeanReference(name + DATA_SOURCE_SUFFIX)); if (element.hasAttribute(TABLE_PREFIX_NAME) && !StringUtil.isEmpty(element.getAttribute(TABLE_PREFIX_NAME))) { AbstractBeanDefinition namingStrategyBeanDefinition = new GenericBeanDefinition(); String randomBeanName = UUID.randomUUID().toString(); namingStrategyBeanDefinition.setAttribute(ID_ATTRIBUTE, randomBeanName); namingStrategyBeanDefinition.setBeanClass(HibernateNamingStrategy.class); MutablePropertyValues mutablePropertyValues = new MutablePropertyValues(); mutablePropertyValues.add("prefix", element.getAttribute(TABLE_PREFIX_NAME)); namingStrategyBeanDefinition.setPropertyValues(mutablePropertyValues); beanDefinitionRegistry.registerBeanDefinition(randomBeanName, namingStrategyBeanDefinition); propertyValues.addPropertyValue("namingStrategy", new RuntimeBeanReference(randomBeanName)); } beanDefinition.setPropertyValues(propertyValues); beanDefinitionParserDelegate.parsePropertyElements(element, beanDefinition); return beanDefinition; }
Example #7
Source File: DataSourceScanner.java From tsharding with MIT License | 6 votes |
/** * 将数据源注入到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); } } }
Example #8
Source File: GlobalBeanDefinitionUtilsTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void retrieveResourceIdResolverBeanName_resourceIdResolverBeanAlreadyRegistered_resourceIdResolverBeanIsNotAgainRegistered() { // @checkstyle:on // Arrange BeanDefinition resourceIdResolverBeanDefinition = new GenericBeanDefinition(); DefaultListableBeanFactory registry = new DefaultListableBeanFactory(); registry.registerBeanDefinition( GlobalBeanDefinitionUtils.RESOURCE_ID_RESOLVER_BEAN_NAME, resourceIdResolverBeanDefinition); // Act GlobalBeanDefinitionUtils.retrieveResourceIdResolverBeanName(registry); // Assert assertThat(registry.getBeanDefinition( GlobalBeanDefinitionUtils.RESOURCE_ID_RESOLVER_BEAN_NAME)) .isEqualTo(resourceIdResolverBeanDefinition); }
Example #9
Source File: BeanDefinitionUtils.java From engine with GNU General Public License v3.0 | 6 votes |
/** * Creates a bean definition for the specified bean name. If the parent context of the current context contains a * bean definition with the same name, the definition is created as a bean copy of the parent definition. This * method is useful for config parsers that want to create a bean definition from configuration but also want to * retain the default properties of the original bean. * * @param applicationContext the current application context * @param beanName * @return the bean definition */ public static BeanDefinition createBeanDefinitionFromOriginal(ApplicationContext applicationContext, String beanName) { ApplicationContext parentContext = applicationContext.getParent(); BeanDefinition parentDefinition = null; if (parentContext != null && parentContext.getAutowireCapableBeanFactory() instanceof ConfigurableListableBeanFactory) { ConfigurableListableBeanFactory parentBeanFactory = (ConfigurableListableBeanFactory)parentContext .getAutowireCapableBeanFactory(); try { parentDefinition = parentBeanFactory.getBeanDefinition(beanName); } catch (NoSuchBeanDefinitionException e) {} } if (parentDefinition != null) { return new GenericBeanDefinition(parentDefinition); } else { return new GenericBeanDefinition(); } }
Example #10
Source File: PluginInvokePostProcessor.java From springboot-plugin-framework-parent with Apache License 2.0 | 6 votes |
/** * 处理调用者 * @param pluginRegistryInfo 插件注册的信息 * @param callerClasses 调用者集合 * @throws Exception 处理异常 */ private void processCaller(PluginRegistryInfo pluginRegistryInfo, List<Class<?>> callerClasses) throws Exception { if(callerClasses == null || callerClasses.isEmpty()){ return; } Set<String> beanNames = new HashSet<>(); String pluginId = pluginRegistryInfo.getPluginWrapper().getPluginId(); for (Class<?> callerClass : callerClasses) { Caller caller = callerClass.getAnnotation(Caller.class); if(caller == null){ continue; } Object supper = applicationContext.getBean(caller.value()); if(supper == null){ return; } String beanName = springBeanRegister.register(pluginId, callerClass, (beanDefinition) ->{ beanDefinition.getPropertyValues().add("callerInterface", callerClass); beanDefinition.getPropertyValues().add("supper", supper); beanDefinition.setBeanClass(CallerInterfaceFactory.class); beanDefinition.setAutowireMode(GenericBeanDefinition.AUTOWIRE_BY_TYPE); }); beanNames.add(beanName); } pluginRegistryInfo.addProcessorInfo(getKey(KEY_CALLERS, pluginRegistryInfo), beanNames); }
Example #11
Source File: BaseBeanFactory.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) public List<BeanDefinitionHolder> createBeans(Map<String, Object> parameters) throws RuntimeConfigException { GenericBeanDefinition def = new GenericBeanDefinition(); def.setBeanClassName(className); MutablePropertyValues propertyValues = new MutablePropertyValues(); List<NamedObject> namedObjects = new ArrayList<NamedObject>(); if (checkCollection(BEAN_REFS, NamedObject.class, parameters) != Priority.NONE) { namedObjects.addAll((Collection) parameters.get(BEAN_REFS)); } for (String name : parameters.keySet()) { if (!ignoredParams.contains(name)) { propertyValues.addPropertyValue(name, beanDefinitionDtoConverterService .createBeanMetadataElementByIntrospection(parameters.get(name), namedObjects)); } } def.setPropertyValues(propertyValues); BeanDefinitionHolder holder = new BeanDefinitionHolder(def, (String) parameters.get(BEAN_NAME)); List<BeanDefinitionHolder> holders = new ArrayList<BeanDefinitionHolder>(); holders.add(holder); return holders; }
Example #12
Source File: NettyRpcClientBeanDefinitionRegistrar.java From spring-boot-protocol with Apache License 2.0 | 6 votes |
@Override public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) { GenericBeanDefinition beanPostProcessorDefinition = new GenericBeanDefinition(); beanPostProcessorDefinition.setInstanceSupplier(()->this); beanPostProcessorDefinition.setBeanClass(BeanPostProcessor.class); registry.registerBeanDefinition("NettyRpcClientBeanPostProcessor",beanPostProcessorDefinition); ClassPathScanningCandidateComponentProvider scanner = getScanner(); scanner.setResourceLoader(resourceLoader); scanner.addIncludeFilter(new AnnotationTypeFilter(NettyRpcClient.class)); Map<String, Object> enableNettyRpcClientsAttributes = metadata.getAnnotationAttributes(enableNettyRpcClientsCanonicalName); for (String basePackage : getBasePackages(metadata,enableNettyRpcClientsAttributes)) { for (BeanDefinition candidateComponent : scanner.findCandidateComponents(basePackage)) { if (!(candidateComponent instanceof AnnotatedBeanDefinition)) { continue; } AnnotatedBeanDefinition beanDefinition = (AnnotatedBeanDefinition) candidateComponent; if(!beanDefinition.getMetadata().isInterface()) { throw new IllegalArgumentException("@NettyRpcClient can only be specified on an interface"); } registerNettyRpcClient(beanDefinition,registry); } } }
Example #13
Source File: GroovyBeanDefinitionWrapper.java From lams with GNU General Public License v2.0 | 6 votes |
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; }
Example #14
Source File: BeanDefinitionDtoConverterServiceImpl.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
/** * Convert from a DTO to an internal Spring bean definition. * * @param beanDefinitionDto The DTO object. * @return Returns a Spring bean definition. */ public BeanDefinition toInternal(BeanDefinitionInfo beanDefinitionInfo) { if (beanDefinitionInfo instanceof GenericBeanDefinitionInfo) { GenericBeanDefinitionInfo genericInfo = (GenericBeanDefinitionInfo) beanDefinitionInfo; GenericBeanDefinition def = new GenericBeanDefinition(); def.setBeanClassName(genericInfo.getClassName()); if (genericInfo.getPropertyValues() != null) { MutablePropertyValues propertyValues = new MutablePropertyValues(); for (Entry<String, BeanMetadataElementInfo> entry : genericInfo.getPropertyValues().entrySet()) { BeanMetadataElementInfo info = entry.getValue(); propertyValues.add(entry.getKey(), toInternal(info)); } def.setPropertyValues(propertyValues); } return def; } else if (beanDefinitionInfo instanceof ObjectBeanDefinitionInfo) { ObjectBeanDefinitionInfo objectInfo = (ObjectBeanDefinitionInfo) beanDefinitionInfo; return createBeanDefinitionByIntrospection(objectInfo.getObject()); } else { throw new IllegalArgumentException("Conversion to internal of " + beanDefinitionInfo.getClass().getName() + " not implemented"); } }
Example #15
Source File: QualifierAnnotationTests.java From java-technology-stack with MIT License | 6 votes |
@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()); }
Example #16
Source File: DynamicDataSourceRegister.java From Aooms with Apache License 2.0 | 6 votes |
@Override public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry beanDefinitionRegistry) { Map<Object, Object> targetDataSources = new HashMap<Object, Object>(); // 将主数据源添加到更多数据源中 targetDataSources.put(AoomsVar.DEFAULT_DATASOURCE, defaultDataSource); DynamicDataSourceHolder.dataSourceIds.add(AoomsVar.DEFAULT_DATASOURCE); // 添加更多数据源 targetDataSources.putAll(moreDataSources); for (String key : moreDataSources.keySet()) { DynamicDataSourceHolder.dataSourceIds.add(key); } // 创建DynamicDataSource GenericBeanDefinition beanDefinition = new GenericBeanDefinition(); beanDefinition.setBeanClass(DynamicDataSource.class); beanDefinition.setSynthetic(true); MutablePropertyValues mpv = beanDefinition.getPropertyValues(); // 添加属性:AbstractRoutingDataSource.defaultTargetDataSource mpv.addPropertyValue("defaultTargetDataSource", defaultDataSource); mpv.addPropertyValue("targetDataSources", targetDataSources); beanDefinitionRegistry.registerBeanDefinition(AoomsVar.DEFAULT_DATASOURCE, beanDefinition); }
Example #17
Source File: GroovyBeanDefinitionWrapper.java From java-technology-stack with MIT License | 6 votes |
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; }
Example #18
Source File: AbstractEntityService.java From OpERP with MIT License | 5 votes |
@Override public void registerClient(String clientAddress) { System.out.println("Client from " + clientAddress); ApplicationContext context = ServerApp.getApplicationContext(); AutowireCapableBeanFactory factory = context .getAutowireCapableBeanFactory(); BeanDefinitionRegistry registry = (BeanDefinitionRegistry) factory; GenericBeanDefinition beanDefinition = new GenericBeanDefinition(); beanDefinition.setBeanClass(RmiProxyFactoryBean.class); beanDefinition.setAutowireCandidate(true); Class<EM> entityModelInterfaceClass = getEntityModelInterfaceClass(); MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.addPropertyValue("serviceInterface", entityModelInterfaceClass); propertyValues.addPropertyValue("serviceUrl", "rmi://" + clientAddress + ":1099/" + entityModelInterfaceClass.getCanonicalName()); beanDefinition.setPropertyValues(propertyValues); registry.registerBeanDefinition( entityModelInterfaceClass.getCanonicalName(), beanDefinition); EM entityModel = context.getBean(entityModelInterfaceClass); registerEntityModel(entityModel); System.out.println(entityModel); }
Example #19
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 #20
Source File: MulCommonBaseServiceParser.java From zxl with Apache License 2.0 | 5 votes |
private BeanDefinition buildHibernateAdviceBeanDefinition(Element element, String name) { AbstractBeanDefinition beanDefinition = new GenericBeanDefinition(); beanDefinition.setAttribute(ID_ATTRIBUTE, name + HIBERNATE_ADVICE_SUFFIX); beanDefinition.setBeanClass(TransactionInterceptor.class); MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("transactionManager", new RuntimeBeanReference(name + HIBERNATE_TRANSACTION_MANAGER_SUFFIX)); propertyValues.add("transactionAttributeSource", new RuntimeBeanReference(name + TRANSACTION_ATTRIBUTE_SOURCE_SUFFIX)); beanDefinition.setPropertyValues(propertyValues); return beanDefinition; }
Example #21
Source File: DefaultsBeanDefinitionParser.java From jdal with Apache License 2.0 | 5 votes |
/** * @param clazz * @return */ @SuppressWarnings("rawtypes") private BeanDefinitionHolder createBeanDefinition(Class clazz, ParserContext parserContext) { GenericBeanDefinition gbd = new GenericBeanDefinition(); gbd.setBeanClass(clazz); gbd.setInitMethodName(INIT_METHOD_NAME); BeanDefinitionHolder holder = new BeanDefinitionHolder(gbd, parserContext.getReaderContext().generateBeanName(gbd)); return holder; }
Example #22
Source File: AnnotationDrivenBeanDefinitionParser.java From spring4-understanding with Apache License 2.0 | 5 votes |
private GenericBeanDefinition createObjectMapperFactoryDefinition(Object source) { GenericBeanDefinition beanDefinition = new GenericBeanDefinition(); beanDefinition.setBeanClass(Jackson2ObjectMapperFactoryBean.class); beanDefinition.setSource(source); beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); return beanDefinition; }
Example #23
Source File: EmbeddedCassandraContextCustomizer.java From embedded-cassandra with Apache License 2.0 | 5 votes |
private static void registerCassandraInitializerBeanDefinition(CqlDataSet dataSet, ConfigurableApplicationContext context, BeanDefinitionRegistry registry) { GenericBeanDefinition bd = new GenericBeanDefinition(); bd.setBeanClass(CassandraInitializer.class); bd.setLazyInit(false); bd.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); bd.setScope(BeanDefinition.SCOPE_SINGLETON); bd.setInstanceSupplier(() -> new CassandraInitializer(context, dataSet)); registry.registerBeanDefinition(CassandraInitializer.class.getName(), bd); }
Example #24
Source File: EmbeddedCassandraContextCustomizer.java From embedded-cassandra with Apache License 2.0 | 5 votes |
private static void registerCassandraConnectionBeanDefinition(ConfigurableApplicationContext context, BeanDefinitionRegistry registry) { GenericBeanDefinition bd = new GenericBeanDefinition(); bd.setBeanClass(CassandraConnection.class); bd.setDestroyMethodName("close"); bd.setLazyInit(true); bd.setDependsOn(Cassandra.class.getName()); bd.setScope(BeanDefinition.SCOPE_SINGLETON); bd.setInstanceSupplier(new CassandraConnectionSupplier(context)); registry.registerBeanDefinition(CassandraConnection.class.getName(), bd); }
Example #25
Source File: EmbeddedCassandraContextCustomizer.java From embedded-cassandra with Apache License 2.0 | 5 votes |
private static void registerCassandraBeanDefinition(boolean exposeProperties, ConfigurableApplicationContext context, BeanDefinitionRegistry registry) { GenericBeanDefinition bd = new GenericBeanDefinition(); bd.setBeanClass(Cassandra.class); bd.setDestroyMethodName("stop"); bd.setLazyInit(false); bd.setScope(BeanDefinition.SCOPE_SINGLETON); bd.setInstanceSupplier(new CassandraSupplier(exposeProperties, context)); registry.registerBeanDefinition(Cassandra.class.getName(), bd); }
Example #26
Source File: MongoContentAutoConfigureRegistrar.java From spring-content with Apache License 2.0 | 5 votes |
@Override protected void registerContentStoreBeanDefinitions( AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) { AnnotationMetadata metadata = new StandardAnnotationMetadata( EnableMongoContentAutoConfiguration.class); AnnotationAttributes attributes = new AnnotationAttributes( metadata.getAnnotationAttributes(this.getAnnotation().getName())); String[] basePackages = this.getBasePackages(); Set<GenericBeanDefinition> definitions = StoreUtils.getStoreCandidates(this.getEnvironment(), this.getResourceLoader(), basePackages, multipleStoreImplementationsDetected(), getIdentifyingTypes()); this.buildAndRegisterDefinitions(importingClassMetadata, registry, attributes, basePackages, definitions); }
Example #27
Source File: MulCommonBaseServiceParser.java From zxl with Apache License 2.0 | 5 votes |
private BeanDefinition buildCommonBaseDaoBeanDefinition(Element element, String name) { AbstractBeanDefinition beanDefinition = new GenericBeanDefinition(); beanDefinition.setAttribute(ID_ATTRIBUTE, name + COMMON_BASE_DAO_SUFFIX); beanDefinition.setBeanClass(COMMON_BASE_DAO_CLASS); MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("sessionFactory", new RuntimeBeanReference(name + SESSION_FACTORY_SUFFIX)); propertyValues.add("sqlSessionTemplate", new RuntimeBeanReference(name + SQL_SESSION_TEMPLATE_SUFFIX)); propertyValues.add("tablePrefix", element.getAttribute(TABLE_PREFIX_NAME)); beanDefinition.setPropertyValues(propertyValues); return beanDefinition; }
Example #28
Source File: AutowiredAnnotationBeanPostProcessorTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testIncompleteBeanDefinition() { bf.registerBeanDefinition("testBean", new GenericBeanDefinition()); try { bf.getBean("testBean"); fail("Should have thrown BeanCreationException"); } catch (BeanCreationException ex) { assertTrue(ex.getRootCause() instanceof IllegalStateException); } }
Example #29
Source File: ApplicationContextExpressionTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void systemPropertiesSecurityManager() { GenericApplicationContext ac = new GenericApplicationContext(); AnnotationConfigUtils.registerAnnotationConfigProcessors(ac); GenericBeanDefinition bd = new GenericBeanDefinition(); bd.setBeanClass(TestBean.class); bd.getPropertyValues().add("country", "#{systemProperties.country}"); ac.registerBeanDefinition("tb", bd); SecurityManager oldSecurityManager = System.getSecurityManager(); try { System.setProperty("country", "NL"); SecurityManager securityManager = new SecurityManager() { @Override public void checkPropertiesAccess() { throw new AccessControlException("Not Allowed"); } @Override public void checkPermission(Permission perm) { // allow everything else } }; System.setSecurityManager(securityManager); ac.refresh(); TestBean tb = ac.getBean("tb", TestBean.class); assertEquals("NL", tb.getCountry()); } finally { System.setSecurityManager(oldSecurityManager); System.getProperties().remove("country"); } }
Example #30
Source File: AnnotationDrivenBeanDefinitionParser.java From lams with GNU General Public License v2.0 | 5 votes |
private GenericBeanDefinition createObjectMapperFactoryDefinition(Object source) { GenericBeanDefinition beanDefinition = new GenericBeanDefinition(); beanDefinition.setBeanClass(Jackson2ObjectMapperFactoryBean.class); beanDefinition.setSource(source); beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); return beanDefinition; }