Java Code Examples for org.springframework.beans.factory.support.GenericBeanDefinition#setInitMethodName()

The following examples show how to use org.springframework.beans.factory.support.GenericBeanDefinition#setInitMethodName() . 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: DefaultsBeanDefinitionParser.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * @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 2
Source File: DefaultsBeanDefinitionParser.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * @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 3
Source File: RemoteServiceScannerRegistrar.java    From seed with Apache License 2.0 4 votes vote down vote up
private void processBeanDefinitions(Set<BeanDefinitionHolder> beanDefinitions) {
    for(BeanDefinitionHolder holder : beanDefinitions){
        try {
            //获取每个标注了@RemoteService注解的所有属性及其值,得到一个Map
            MetadataReader metadataReader = this.getMetadataReaderFactory().getMetadataReader(holder.getBeanDefinition().getBeanClassName());
            AnnotationAttributes annoAttrs = AnnotationAttributes.fromMap(metadataReader.getAnnotationMetadata().getAnnotationAttributes(RemoteService.class.getName()));
            if(null==annoAttrs || annoAttrs.isEmpty()){
                continue;
            }
            //计算serviceInterface
            Class<?> serviceInterface = annoAttrs.getClass("value");
            if(null == serviceInterface){
                serviceInterface = annoAttrs.getClass("serviceInterface");
            }
            if("java.lang.Class".equals(serviceInterface.getName())){
                throw new IllegalArgumentException("undefined service interface on RemoteService class: " + holder.getBeanDefinition().getBeanClassName());
            }
            //计算服务路径("/" + path + "/" + name)
            String name = annoAttrs.getString("name").trim();
            if(StringUtils.isBlank(name)){
                name = serviceInterface.getSimpleName();
            }
            String path = annoAttrs.getString("path").trim();
            if(StringUtils.isNotBlank(path)){
                if(path.endsWith("/")){
                    name = path + name;
                }else{
                    name = path + "/" + name;
                }
            }
            if(!name.startsWith("/")){
                name = "/" + name;
            }
            //通过Spring提供的HttpInvokerServiceExporter输出服务,该类可以将普通Bean实例输出成远程服务
            //这里是比较关键的:因为我们需要自己设定哪个Bean输出服务,哪个Bean不用输出,所以才自定义注解来实现
            //@RemoteServiceScan和@RemoteService的目的就是找到我们希望输出服务的Bean,然后手工注册Bean并输出
            GenericBeanDefinition definition = new GenericBeanDefinition();
            definition.getPropertyValues().add("service", new RuntimeBeanReference(holder.getBeanName()));
            definition.getPropertyValues().add("serviceInterface", serviceInterface);
            definition.setInitMethodName("afterPropertiesSet");
            definition.setBeanClass(HttpInvokerServiceExporter.class);
            this.registerBeanDefinition(new BeanDefinitionHolder(definition, name), this.getRegistry());
        }catch(IOException e){
            throw new BeanDefinitionStoreException("Failed to read candidate component class: " + holder.getBeanDefinition().getBeanClassName(), e);
        }
    }
}