Java Code Examples for org.springframework.context.annotation.Scope

The following examples show how to use org.springframework.context.annotation.Scope. 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 want to check out the right sidebar which shows the related API usage.
Example 1
@Bean(name = "file-lock-cluster-service")
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
public CamelClusterService fileClusterService() throws Exception {
    FileLockClusterService service = new FileLockClusterService();

    Optional.ofNullable(configuration.getId())
        .ifPresent(service::setId);
    Optional.ofNullable(configuration.getRoot())
        .ifPresent(service::setRoot);
    Optional.ofNullable(configuration.getOrder())
        .ifPresent(service::setOrder);
    Optional.ofNullable(configuration.getAttributes())
        .ifPresent(service::setAttributes);
    Optional.ofNullable(configuration.getAcquireLockDelay())
        .map(TimePatternConverter::toMilliSeconds)
        .ifPresent(v -> service.setAcquireLockDelay(v, TimeUnit.MILLISECONDS));
    Optional.ofNullable(configuration.getAcquireLockInterval())
        .map(TimePatternConverter::toMilliSeconds)
        .ifPresent(v -> service.setAcquireLockInterval(v, TimeUnit.MILLISECONDS));

    return service;
}
 
Example 2
Source Project: WeEvent   Source File: GovernanceApplication.java    License: Apache License 2.0 6 votes vote down vote up
@Scope("prototype")
@Bean("httpClient")
public CloseableHttpClient getHttpClient(GovernanceConfig config) {
    /**
     * config connect parameter
     */
    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();

    RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(config.getConnectionRequestTimeout())
            .setConnectTimeout(config.getHttpConnectTimeOut()).setSocketTimeout(config.getSocketTimeout()).build();

    cm.setMaxTotal(config.getMaxTotal());
    cm.setDefaultMaxPerRoute(config.getMaxPerRoute());
    return HttpClients.custom().setConnectionManager(cm)
            .setDefaultRequestConfig(requestConfig).setRetryHandler(retryHandler).build();
}
 
Example 3
Source Project: WeBASE-Node-Manager   Source File: BeanConfig.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * factory for deploy.
 */
@Bean()
@Scope("prototype")
public SimpleClientHttpRequestFactory getHttpFactoryForDeploy() {
    SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
    return factory;
}
 
Example 4
@Bean
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
public GitHub gitHub(ConnectionRepository repository) {
	Connection<GitHub> connection = repository
			.findPrimaryConnection(GitHub.class);
	return connection != null ? connection.getApi() : null;
}
 
Example 5
@Bean
@Lazy
@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS)
public AnnotationTestBean testBean() {
	AnnotationTestBean bean = new AnnotationTestBean();
	bean.setName("TEST");
	bean.setAge(100);
	return bean;
}
 
Example 6
@Bean(name = "mvel-language")
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@ConditionalOnMissingBean(MvelLanguage.class)
public MvelLanguage configureMvelLanguage() throws Exception {
    MvelLanguage language = new MvelLanguage();
    if (CamelContextAware.class.isAssignableFrom(MvelLanguage.class)) {
        CamelContextAware contextAware = CamelContextAware.class
                .cast(language);
        if (contextAware != null) {
            contextAware.setCamelContext(camelContext);
        }
    }
    Map<String, Object> parameters = new HashMap<>();
    IntrospectionSupport.getProperties(configuration, parameters, null,
            false);
    CamelPropertiesHelper.setCamelProperties(camelContext, language,
            parameters, false);
    if (ObjectHelper.isNotEmpty(customizers)) {
        for (LanguageCustomizer<MvelLanguage> customizer : customizers) {
            boolean useCustomizer = (customizer instanceof HasId)
                    ? HierarchicalPropertiesEvaluator.evaluate(
                            applicationContext.getEnvironment(),
                            "camel.language.customizer",
                            "camel.language.mvel.customizer",
                            ((HasId) customizer).getId())
                    : HierarchicalPropertiesEvaluator.evaluate(
                            applicationContext.getEnvironment(),
                            "camel.language.customizer",
                            "camel.language.mvel.customizer");
            if (useCustomizer) {
                LOGGER.debug("Configure language {}, with customizer {}",
                        language, customizer);
                customizer.customize(language);
            }
        }
    }
    return language;
}
 
Example 7
@Bean(name = "groovy-language")
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@ConditionalOnMissingBean(GroovyLanguage.class)
public GroovyLanguage configureGroovyLanguage() throws Exception {
    GroovyLanguage language = new GroovyLanguage();
    if (CamelContextAware.class.isAssignableFrom(GroovyLanguage.class)) {
        CamelContextAware contextAware = CamelContextAware.class
                .cast(language);
        if (contextAware != null) {
            contextAware.setCamelContext(camelContext);
        }
    }
    Map<String, Object> parameters = new HashMap<>();
    IntrospectionSupport.getProperties(configuration, parameters, null,
            false);
    CamelPropertiesHelper.setCamelProperties(camelContext, language,
            parameters, false);
    if (ObjectHelper.isNotEmpty(customizers)) {
        for (LanguageCustomizer<GroovyLanguage> customizer : customizers) {
            boolean useCustomizer = (customizer instanceof HasId)
                    ? HierarchicalPropertiesEvaluator.evaluate(
                            applicationContext.getEnvironment(),
                            "camel.language.customizer",
                            "camel.language.groovy.customizer",
                            ((HasId) customizer).getId())
                    : HierarchicalPropertiesEvaluator.evaluate(
                            applicationContext.getEnvironment(),
                            "camel.language.customizer",
                            "camel.language.groovy.customizer");
            if (useCustomizer) {
                LOGGER.debug("Configure language {}, with customizer {}",
                        language, customizer);
                customizer.customize(language);
            }
        }
    }
    return language;
}
 
Example 8
@Bean(name = "jgroups-lock-cluster-service")
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
public CamelClusterService zookeeperClusterService() throws Exception {
    JGroupsLockClusterService service = new JGroupsLockClusterService();

    IntrospectionSupport.setProperties(
        service,
        IntrospectionSupport.getNonNullProperties(configuration)
    );

    return service;
}
 
Example 9
@Bean(name = "kubernetes-cluster-service")
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
public CamelClusterService kubernetesClusterService() throws Exception {
    KubernetesClusterService service = new KubernetesClusterService();

    IntrospectionSupport.setProperties(
        service,
        IntrospectionSupport.getNonNullProperties(configuration)
    );

    return service;
}
 
Example 10
@Bean(name = "zookeeper-service-registry")
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
public ZooKeeperServiceRegistry zookeeperServiceRegistry(ZooKeeperServiceRegistryConfiguration configuration) throws Exception {
    ZooKeeperServiceRegistry service = new ZooKeeperServiceRegistry();

    IntrospectionSupport.setProperties(
        service,
        IntrospectionSupport.getNonNullProperties(configuration)
    );

    return service;
}
 
Example 11
@Bean(name = "zookeeper-cluster-service")
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
public CamelClusterService zookeeperClusterService() throws Exception {
    ZooKeeperClusterService service = new ZooKeeperClusterService();

    IntrospectionSupport.setProperties(
        service,
        IntrospectionSupport.getNonNullProperties(configuration)
    );

    return service;
}
 
Example 12
@Bean(name = "xtokenize-language")
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@ConditionalOnMissingBean(XMLTokenizeLanguage.class)
public XMLTokenizeLanguage configureXMLTokenizeLanguage() throws Exception {
    XMLTokenizeLanguage language = new XMLTokenizeLanguage();
    if (CamelContextAware.class.isAssignableFrom(XMLTokenizeLanguage.class)) {
        CamelContextAware contextAware = CamelContextAware.class
                .cast(language);
        if (contextAware != null) {
            contextAware.setCamelContext(camelContext);
        }
    }
    Map<String, Object> parameters = new HashMap<>();
    IntrospectionSupport.getProperties(configuration, parameters, null,
            false);
    CamelPropertiesHelper.setCamelProperties(camelContext, language,
            parameters, false);
    if (ObjectHelper.isNotEmpty(customizers)) {
        for (LanguageCustomizer<XMLTokenizeLanguage> customizer : customizers) {
            boolean useCustomizer = (customizer instanceof HasId)
                    ? HierarchicalPropertiesEvaluator.evaluate(
                            applicationContext.getEnvironment(),
                            "camel.language.customizer",
                            "camel.language.xtokenize.customizer",
                            ((HasId) customizer).getId())
                    : HierarchicalPropertiesEvaluator.evaluate(
                            applicationContext.getEnvironment(),
                            "camel.language.customizer",
                            "camel.language.xtokenize.customizer");
            if (useCustomizer) {
                LOGGER.debug("Configure language {}, with customizer {}",
                        language, customizer);
                customizer.customize(language);
            }
        }
    }
    return language;
}
 
Example 13
@Bean(name = "jsonpath-language")
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@ConditionalOnMissingBean(JsonPathLanguage.class)
public JsonPathLanguage configureJsonPathLanguage() throws Exception {
    JsonPathLanguage language = new JsonPathLanguage();
    if (CamelContextAware.class.isAssignableFrom(JsonPathLanguage.class)) {
        CamelContextAware contextAware = CamelContextAware.class
                .cast(language);
        if (contextAware != null) {
            contextAware.setCamelContext(camelContext);
        }
    }
    Map<String, Object> parameters = new HashMap<>();
    IntrospectionSupport.getProperties(configuration, parameters, null,
            false);
    CamelPropertiesHelper.setCamelProperties(camelContext, language,
            parameters, false);
    if (ObjectHelper.isNotEmpty(customizers)) {
        for (LanguageCustomizer<JsonPathLanguage> customizer : customizers) {
            boolean useCustomizer = (customizer instanceof HasId)
                    ? HierarchicalPropertiesEvaluator.evaluate(
                            applicationContext.getEnvironment(),
                            "camel.language.customizer",
                            "camel.language.jsonpath.customizer",
                            ((HasId) customizer).getId())
                    : HierarchicalPropertiesEvaluator.evaluate(
                            applicationContext.getEnvironment(),
                            "camel.language.customizer",
                            "camel.language.jsonpath.customizer");
            if (useCustomizer) {
                LOGGER.debug("Configure language {}, with customizer {}",
                        language, customizer);
                customizer.customize(language);
            }
        }
    }
    return language;
}
 
Example 14
@Bean(name = "consul-service-registry")
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
public ConsulServiceRegistry consulServiceRegistry(ConsulServiceRegistryConfiguration configuration) throws Exception {
    ConsulServiceRegistry service = new ConsulServiceRegistry();

    IntrospectionSupport.setProperties(
        service,
        IntrospectionSupport.getNonNullProperties(configuration)
    );

    return service;
}
 
Example 15
@Bean(name = "consul-cluster-service")
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
public CamelClusterService consulClusterService() throws Exception {
    ConsulClusterService service = new ConsulClusterService();

    IntrospectionSupport.setProperties(
        service,
        IntrospectionSupport.getNonNullProperties(configuration)
    );

    return service;
}
 
Example 16
@Bean(name = "xquery-language")
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@ConditionalOnMissingBean(XQueryLanguage.class)
public XQueryLanguage configureXQueryLanguage() throws Exception {
    XQueryLanguage language = new XQueryLanguage();
    if (CamelContextAware.class.isAssignableFrom(XQueryLanguage.class)) {
        CamelContextAware contextAware = CamelContextAware.class
                .cast(language);
        if (contextAware != null) {
            contextAware.setCamelContext(camelContext);
        }
    }
    Map<String, Object> parameters = new HashMap<>();
    IntrospectionSupport.getProperties(configuration, parameters, null,
            false);
    CamelPropertiesHelper.setCamelProperties(camelContext, language,
            parameters, false);
    if (ObjectHelper.isNotEmpty(customizers)) {
        for (LanguageCustomizer<XQueryLanguage> customizer : customizers) {
            boolean useCustomizer = (customizer instanceof HasId)
                    ? HierarchicalPropertiesEvaluator.evaluate(
                            applicationContext.getEnvironment(),
                            "camel.language.customizer",
                            "camel.language.xquery.customizer",
                            ((HasId) customizer).getId())
                    : HierarchicalPropertiesEvaluator.evaluate(
                            applicationContext.getEnvironment(),
                            "camel.language.customizer",
                            "camel.language.xquery.customizer");
            if (useCustomizer) {
                LOGGER.debug("Configure language {}, with customizer {}",
                        language, customizer);
                customizer.customize(language);
            }
        }
    }
    return language;
}
 
Example 17
@Bean(name = "hl7terser-language")
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@ConditionalOnMissingBean(Hl7TerserLanguage.class)
public Hl7TerserLanguage configureHl7TerserLanguage() throws Exception {
    Hl7TerserLanguage language = new Hl7TerserLanguage();
    if (CamelContextAware.class.isAssignableFrom(Hl7TerserLanguage.class)) {
        CamelContextAware contextAware = CamelContextAware.class
                .cast(language);
        if (contextAware != null) {
            contextAware.setCamelContext(camelContext);
        }
    }
    Map<String, Object> parameters = new HashMap<>();
    IntrospectionSupport.getProperties(configuration, parameters, null,
            false);
    CamelPropertiesHelper.setCamelProperties(camelContext, language,
            parameters, false);
    if (ObjectHelper.isNotEmpty(customizers)) {
        for (LanguageCustomizer<Hl7TerserLanguage> customizer : customizers) {
            boolean useCustomizer = (customizer instanceof HasId)
                    ? HierarchicalPropertiesEvaluator.evaluate(
                            applicationContext.getEnvironment(),
                            "camel.language.customizer",
                            "camel.language.hl7terser.customizer",
                            ((HasId) customizer).getId())
                    : HierarchicalPropertiesEvaluator.evaluate(
                            applicationContext.getEnvironment(),
                            "camel.language.customizer",
                            "camel.language.hl7terser.customizer");
            if (useCustomizer) {
                LOGGER.debug("Configure language {}, with customizer {}",
                        language, customizer);
                customizer.customize(language);
            }
        }
    }
    return language;
}
 
Example 18
@Bean(name = "jgroups-raft-cluster-service")
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
public CamelClusterService jgroupsRaftClusterService() throws Exception {
    JGroupsRaftClusterService service = new JGroupsRaftClusterService();

    IntrospectionSupport.setProperties(
        service,
        IntrospectionSupport.getNonNullProperties(configuration)
    );

    return service;
}
 
Example 19
@Bean(name = "constant-language")
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@ConditionalOnMissingBean(ConstantLanguage.class)
public ConstantLanguage configureConstantLanguage() throws Exception {
    ConstantLanguage language = new ConstantLanguage();
    if (CamelContextAware.class.isAssignableFrom(ConstantLanguage.class)) {
        CamelContextAware contextAware = CamelContextAware.class
                .cast(language);
        if (contextAware != null) {
            contextAware.setCamelContext(camelContext);
        }
    }
    Map<String, Object> parameters = new HashMap<>();
    IntrospectionSupport.getProperties(configuration, parameters, null,
            false);
    CamelPropertiesHelper.setCamelProperties(camelContext, language,
            parameters, false);
    if (ObjectHelper.isNotEmpty(customizers)) {
        for (LanguageCustomizer<ConstantLanguage> customizer : customizers) {
            boolean useCustomizer = (customizer instanceof HasId)
                    ? HierarchicalPropertiesEvaluator.evaluate(
                            applicationContext.getEnvironment(),
                            "camel.language.customizer",
                            "camel.language.constant.customizer",
                            ((HasId) customizer).getId())
                    : HierarchicalPropertiesEvaluator.evaluate(
                            applicationContext.getEnvironment(),
                            "camel.language.customizer",
                            "camel.language.constant.customizer");
            if (useCustomizer) {
                LOGGER.debug("Configure language {}, with customizer {}",
                        language, customizer);
                customizer.customize(language);
            }
        }
    }
    return language;
}
 
Example 20
@Bean(name = "exchangeProperty-language")
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@ConditionalOnMissingBean(ExchangePropertyLanguage.class)
public ExchangePropertyLanguage configureExchangePropertyLanguage()
        throws Exception {
    ExchangePropertyLanguage language = new ExchangePropertyLanguage();
    if (CamelContextAware.class.isAssignableFrom(ExchangePropertyLanguage.class)) {
        CamelContextAware contextAware = CamelContextAware.class
                .cast(language);
        if (contextAware != null) {
            contextAware.setCamelContext(camelContext);
        }
    }
    Map<String, Object> parameters = new HashMap<>();
    IntrospectionSupport.getProperties(configuration, parameters, null,
            false);
    CamelPropertiesHelper.setCamelProperties(camelContext, language,
            parameters, false);
    if (ObjectHelper.isNotEmpty(customizers)) {
        for (LanguageCustomizer<ExchangePropertyLanguage> customizer : customizers) {
            boolean useCustomizer = (customizer instanceof HasId)
                    ? HierarchicalPropertiesEvaluator.evaluate(
                            applicationContext.getEnvironment(),
                            "camel.language.customizer",
                            "camel.language.exchangeproperty.customizer",
                            ((HasId) customizer).getId())
                    : HierarchicalPropertiesEvaluator.evaluate(
                            applicationContext.getEnvironment(),
                            "camel.language.customizer",
                            "camel.language.exchangeproperty.customizer");
            if (useCustomizer) {
                LOGGER.debug("Configure language {}, with customizer {}",
                        language, customizer);
                customizer.customize(language);
            }
        }
    }
    return language;
}
 
Example 21
@Bean(name = "ref-language")
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@ConditionalOnMissingBean(RefLanguage.class)
public RefLanguage configureRefLanguage() throws Exception {
    RefLanguage language = new RefLanguage();
    if (CamelContextAware.class.isAssignableFrom(RefLanguage.class)) {
        CamelContextAware contextAware = CamelContextAware.class
                .cast(language);
        if (contextAware != null) {
            contextAware.setCamelContext(camelContext);
        }
    }
    Map<String, Object> parameters = new HashMap<>();
    IntrospectionSupport.getProperties(configuration, parameters, null,
            false);
    CamelPropertiesHelper.setCamelProperties(camelContext, language,
            parameters, false);
    if (ObjectHelper.isNotEmpty(customizers)) {
        for (LanguageCustomizer<RefLanguage> customizer : customizers) {
            boolean useCustomizer = (customizer instanceof HasId)
                    ? HierarchicalPropertiesEvaluator.evaluate(
                            applicationContext.getEnvironment(),
                            "camel.language.customizer",
                            "camel.language.ref.customizer",
                            ((HasId) customizer).getId())
                    : HierarchicalPropertiesEvaluator.evaluate(
                            applicationContext.getEnvironment(),
                            "camel.language.customizer",
                            "camel.language.ref.customizer");
            if (useCustomizer) {
                LOGGER.debug("Configure language {}, with customizer {}",
                        language, customizer);
                customizer.customize(language);
            }
        }
    }
    return language;
}
 
Example 22
@Bean(name = "tokenize-language")
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@ConditionalOnMissingBean(TokenizeLanguage.class)
public TokenizeLanguage configureTokenizeLanguage() throws Exception {
    TokenizeLanguage language = new TokenizeLanguage();
    if (CamelContextAware.class.isAssignableFrom(TokenizeLanguage.class)) {
        CamelContextAware contextAware = CamelContextAware.class
                .cast(language);
        if (contextAware != null) {
            contextAware.setCamelContext(camelContext);
        }
    }
    Map<String, Object> parameters = new HashMap<>();
    IntrospectionSupport.getProperties(configuration, parameters, null,
            false);
    CamelPropertiesHelper.setCamelProperties(camelContext, language,
            parameters, false);
    if (ObjectHelper.isNotEmpty(customizers)) {
        for (LanguageCustomizer<TokenizeLanguage> customizer : customizers) {
            boolean useCustomizer = (customizer instanceof HasId)
                    ? HierarchicalPropertiesEvaluator.evaluate(
                            applicationContext.getEnvironment(),
                            "camel.language.customizer",
                            "camel.language.tokenize.customizer",
                            ((HasId) customizer).getId())
                    : HierarchicalPropertiesEvaluator.evaluate(
                            applicationContext.getEnvironment(),
                            "camel.language.customizer",
                            "camel.language.tokenize.customizer");
            if (useCustomizer) {
                LOGGER.debug("Configure language {}, with customizer {}",
                        language, customizer);
                customizer.customize(language);
            }
        }
    }
    return language;
}
 
Example 23
@Bean
@Lazy
@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS)
public AnnotationTestBean testBean() {
	AnnotationTestBean bean = new AnnotationTestBean();
	bean.setName("TEST");
	bean.setAge(100);
	return bean;
}
 
Example 24
/**
 * Feign Spring 表单编码器
 * @return 表单编码器
 */
@Bean
@Primary
@Scope("prototype")
public Encoder multipartEncoder(){
    return new SpringFormEncoder();
}
 
Example 25
Source Project: chronus   Source File: DubboConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean(name = "DUBBO")
@Scope("prototype")
@ConditionalOnMissingBean
public DubboJobDispatcherImpl jobByDubboType(ChronusSdkProcessor chronusSdkFacade) {
    DubboJobDispatcherImpl dubboJobDispatcher = new DubboJobDispatcherImpl(chronusSdkFacade);
    return dubboJobDispatcher;
}
 
Example 26
Source Project: spring-analysis-note   Source File: AutowiredConfigurationTests.java    License: MIT License 4 votes vote down vote up
@Bean @Scope("prototype")
public TestBean testBean() {
	return new TestBean(name);
}
 
Example 27
Source Project: spring-analysis-note   Source File: AutowiredConfigurationTests.java    License: MIT License 4 votes vote down vote up
@Bean @Scope("prototype")
public TestBean testBean2() {
	return new TestBean(name2);
}
 
Example 28
Source Project: spring-analysis-note   Source File: AutowiredConfigurationTests.java    License: MIT License 4 votes vote down vote up
@Bean @Scope("prototype")
public TestBean testBean() {
	return new TestBean(name);
}
 
Example 29
Source Project: spring-analysis-note   Source File: AutowiredConfigurationTests.java    License: MIT License 4 votes vote down vote up
@Bean @Scope("prototype")
public TestBean testBean2() {
	return new TestBean(name2);
}
 
Example 30
@Bean @Scope("prototype")
public TestBean testBean() {
	return new TestBean(name);
}