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

The following examples show how to use org.springframework.beans.factory.support.BeanDefinitionBuilder#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: MqProducerBeanFactory.java    From paascloud-master with Apache License 2.0 6 votes vote down vote up
/**
 * Build producer bean.
 *
 * @param producerDto the producer dto
 */
public static void buildProducerBean(ReliableMessageRegisterDto producerDto) {

	String pid = producerDto.getProducerGroup();
	DefaultMQProducer mQProducer = DEFAULT_MQ_PRODUCER_MAP.get(pid);
	if (mQProducer == null) {
		String simpleName = producerDto.getProducerGroup();
		BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.rootBeanDefinition(DefaultMQProducer.class);
		beanDefinitionBuilder.setScope(BeanDefinition.SCOPE_SINGLETON);
		beanDefinitionBuilder.addPropertyValue("producerGroup", producerDto.getProducerGroup());
		beanDefinitionBuilder.addPropertyValue("namesrvAddr", producerDto.getNamesrvAddr());
		beanDefinitionBuilder.setInitMethodName("start");
		beanDefinitionBuilder.setDestroyMethodName("shutdown");
		SpringContextHolder.getDefaultListableBeanFactory().registerBeanDefinition(simpleName, beanDefinitionBuilder.getBeanDefinition());
		DEFAULT_MQ_PRODUCER_MAP.put(simpleName, SpringContextHolder.getBean(simpleName));
	}
}
 
Example 2
Source File: GeneratorBeanDefinitionParser.java    From idworker with Apache License 2.0 6 votes vote down vote up
@Override
protected AbstractBeanDefinition parseInternal(final Element element, final ParserContext parserContext) {
    Class<?> generatorClass = null;
    if (ConfigConstants.SNOWFLAKE.equals(generatorType)) {
        generatorClass = SnowflakeGenerator.class;
    } else if (ConfigConstants.COMPRESS_UUID.equals(generatorType)) {
        generatorClass = CompressUUIDGenerator.class;
    } else {
        throw new IllegalArgumentException("unknown registryType");
    }
    BeanDefinitionBuilder result = BeanDefinitionBuilder.rootBeanDefinition(generatorClass);
    // snowflake 生成策略
    if (generatorClass.isAssignableFrom(SnowflakeGenerator.class)) {
        result.addConstructorArgValue(
                GeneratorRegisteryBuilder.buildWorkerNodeRegisterBeanDefinition(element, parserContext));
        // 去掉低并发模式配置解析
        // result.addPropertyValue(PropertyConstants.LOW_CONCURRENCY,
        // getAttributeValue(element,
        // GeneratorBeanDefinitionTag.LOW_CONCURRENCY));
        result.setInitMethodName("init");
    }
    return result.getBeanDefinition();
}
 
Example 3
Source File: AbstractDataBaseBean.java    From spring-boot-starter-dao with Apache License 2.0 5 votes vote down vote up
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 4
Source File: ZookeeperBeanDefinitionParser.java    From shardingsphere-elasticjob-lite with Apache License 2.0 5 votes vote down vote up
@Override
protected AbstractBeanDefinition parseInternal(final Element element, final ParserContext parserContext) {
    BeanDefinitionBuilder result = BeanDefinitionBuilder.rootBeanDefinition(ZookeeperRegistryCenter.class);
    result.addConstructorArgValue(buildZookeeperConfigurationBeanDefinition(element));
    result.setInitMethodName("init");
    return result.getBeanDefinition();
}
 
Example 5
Source File: AbstractJobBeanDefinitionParser.java    From shardingsphere-elasticjob-lite with Apache License 2.0 5 votes vote down vote up
@SneakyThrows
@Override
protected final AbstractBeanDefinition parseInternal(final Element element, final ParserContext parserContext) {
    BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(JobScheduler.class);
    factory.setInitMethodName("init");
    factory.addConstructorArgReference(element.getAttribute(BaseJobBeanDefinitionParserTag.REGISTRY_CENTER_REF_ATTRIBUTE));
    factory.addConstructorArgReference(element.getAttribute(BaseJobBeanDefinitionParserTag.JOB_REF_ATTRIBUTE));
    factory.addConstructorArgValue(createJobConfiguration(element));
    BeanDefinition tracingConfig = createTracingConfiguration(element);
    if (null != tracingConfig) {
        factory.addConstructorArgValue(tracingConfig);
    }
    factory.addConstructorArgValue(createJobListeners(element));
    return factory.getBeanDefinition();
}
 
Example 6
Source File: ServerFactoryBeanDefinitionParser.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
protected void doParse(Element element, ParserContext ctx, BeanDefinitionBuilder bean) {
    super.doParse(element, ctx, bean);

    bean.setInitMethodName("create");
    bean.setDestroyMethodName("destroy");

    // We don't really want to delay the registration of our Server
    bean.setLazyInit(false);
}
 
Example 7
Source File: JAXRSServerFactoryBeanDefinitionParser.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
protected void doParse(Element element, ParserContext ctx, BeanDefinitionBuilder bean) {
    super.doParse(element, ctx, bean);

    bean.setInitMethodName("create");
    bean.setDestroyMethodName("destroy");

    // We don't really want to delay the registration of our Server
    bean.setLazyInit(false);
}
 
Example 8
Source File: RMTxStoreBeanDefinitionParser.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Override
protected void doParse(Element element, ParserContext ctx, BeanDefinitionBuilder bean) {
    super.doParse(element, ctx, bean);
    bean.setInitMethodName("init");
    bean.setDestroyMethodName("destroy");
}