org.springframework.beans.factory.config.BeanDefinition#SCOPE_SINGLETON源码实例Demo

下面列出了org.springframework.beans.factory.config.BeanDefinition#SCOPE_SINGLETON 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: sourcerer   文件: SourcererEventConfiguration.java
@Bean
@Lazy
@Scope(BeanDefinition.SCOPE_SINGLETON)
EventSubscriptionFactory<T> getEventSubscriptionFactory(
        final EventRepository<T> eventRepository) {
    return new DefaultEventSubscriptionFactory<>(eventRepository);
}
 
源代码2 项目: sourcerer   文件: SourcererCommandConfiguration.java
@Bean
@Lazy
@Scope(BeanDefinition.SCOPE_SINGLETON)
public AggregateRepository<TState, TEvent> getAggregateRepository(
        final EventRepository<TEvent> eventRepository) {
    return new DefaultAggregateRepository<>(eventRepository, projection, this::resolveType);
}
 
源代码3 项目: sourcerer   文件: SourcererCommandConfiguration.java
@Bean
@Lazy
@Scope(BeanDefinition.SCOPE_SINGLETON)
public CommandFactory<TState, TEvent> getCommandFactory(
        final AggregateRepository<TState, TEvent> aggregateRepository) {
    List<CommandPostProcessor> commandPostProcessors = new ArrayList<>();
    if (metadataDecorators != null) {
        for (MetadataDecorator metadataDecorator : metadataDecorators) {
            commandPostProcessors.add(
                    new MetadataDecoratorCommandPostProcessor(metadataDecorator));
        }
    }

    return new DefaultCommandFactory<>(aggregateRepository, commandPostProcessors);
}
 
源代码4 项目: sourcerer   文件: EventStoreConfiguration.java
@Bean
@Scope(BeanDefinition.SCOPE_SINGLETON)
public EventStore getEventStoreConnection(
        @Value("${sourcerer.eventstore.hostname:127.0.0.1}") final String hostname,
        @Value("${sourcerer.eventstore.port:1113}") final int port,
        @Value("${sourcerer.eventstore.gossipPort:2113}") final int gossipPort,
        @Value("${sourcerer.eventstore.requireMaster:false}") final boolean requireMaster,
        @Value("${sourcerer.eventstore.useClusterDiscovery:false}")
        final boolean useClusterDiscovery) {
    EventStoreBuilder builder = EventStoreBuilder
            .newBuilder()
            .userCredentials("admin", "changeit")
            .requireMaster(requireMaster)
            .failOnNoServerResponse(true);

    if (useClusterDiscovery) {
        builder
                .clusterNodeUsingDns(dnsConfig -> dnsConfig
                        .dns(hostname)
                        .externalGossipPort(gossipPort)
                        .maxDiscoverAttempts(10)
                        .discoverAttemptInterval(Duration.ofMillis(500)));
    } else {
        builder.singleNodeAddress(hostname, port);
    }

    return builder.build();
}
 
源代码5 项目: sourcerer   文件: EventStoreConfiguration.java
@Bean
@Scope(BeanDefinition.SCOPE_SINGLETON)
public EventRepositoryFactory getEventRepositoryFactory(
        final EventStore eventStore,
        final ObjectMapper objectMapper,
        @Value("${sourcerer.eventstore.namespace}") final String namespace) {
    return new EventStoreEsjcEventRepositoryFactory(eventStore, objectMapper, namespace.trim());
}
 
源代码6 项目: sourcerer   文件: EventStoreConfiguration.java
@Bean
@Scope(BeanDefinition.SCOPE_SINGLETON)
public EventRepositoryFactory getEventRepositoryFactory(
        final EsConnection connection,
        final ObjectMapper objectMapper,
        @Value("${sourcerer.eventstore.namespace}") final String namespace) {
    return new EventStoreEventRepositoryFactory(connection, objectMapper, namespace.trim());
}
 
源代码7 项目: spring-analysis-note   文件: LiveBeansView.java
/**
 * Actually generate a JSON snapshot of the beans in the given ApplicationContexts.
 * <p>This implementation doesn't use any JSON parsing libraries in order to avoid
 * third-party library dependencies. It produces an array of context description
 * objects, each containing a context and parent attribute as well as a beans
 * attribute with nested bean description objects. Each bean object contains a
 * bean, scope, type and resource attribute, as well as a dependencies attribute
 * with a nested array of bean names that the present bean depends on.
 * @param contexts the set of ApplicationContexts
 * @return the JSON document
 */
protected String generateJson(Set<ConfigurableApplicationContext> contexts) {
	StringBuilder result = new StringBuilder("[\n");
	for (Iterator<ConfigurableApplicationContext> it = contexts.iterator(); it.hasNext();) {
		ConfigurableApplicationContext context = it.next();
		result.append("{\n\"context\": \"").append(context.getId()).append("\",\n");
		if (context.getParent() != null) {
			result.append("\"parent\": \"").append(context.getParent().getId()).append("\",\n");
		}
		else {
			result.append("\"parent\": null,\n");
		}
		result.append("\"beans\": [\n");
		ConfigurableListableBeanFactory bf = context.getBeanFactory();
		String[] beanNames = bf.getBeanDefinitionNames();
		boolean elementAppended = false;
		for (String beanName : beanNames) {
			BeanDefinition bd = bf.getBeanDefinition(beanName);
			if (isBeanEligible(beanName, bd, bf)) {
				if (elementAppended) {
					result.append(",\n");
				}
				result.append("{\n\"bean\": \"").append(beanName).append("\",\n");
				result.append("\"aliases\": ");
				appendArray(result, bf.getAliases(beanName));
				result.append(",\n");
				String scope = bd.getScope();
				if (!StringUtils.hasText(scope)) {
					scope = BeanDefinition.SCOPE_SINGLETON;
				}
				result.append("\"scope\": \"").append(scope).append("\",\n");
				Class<?> beanType = bf.getType(beanName);
				if (beanType != null) {
					result.append("\"type\": \"").append(beanType.getName()).append("\",\n");
				}
				else {
					result.append("\"type\": null,\n");
				}
				result.append("\"resource\": \"").append(getEscapedResourceDescription(bd)).append("\",\n");
				result.append("\"dependencies\": ");
				appendArray(result, bf.getDependenciesForBean(beanName));
				result.append("\n}");
				elementAppended = true;
			}
		}
		result.append("]\n");
		result.append("}");
		if (it.hasNext()) {
			result.append(",\n");
		}
	}
	result.append("]");
	return result.toString();
}
 
源代码8 项目: java-technology-stack   文件: LiveBeansView.java
/**
 * Actually generate a JSON snapshot of the beans in the given ApplicationContexts.
 * <p>This implementation doesn't use any JSON parsing libraries in order to avoid
 * third-party library dependencies. It produces an array of context description
 * objects, each containing a context and parent attribute as well as a beans
 * attribute with nested bean description objects. Each bean object contains a
 * bean, scope, type and resource attribute, as well as a dependencies attribute
 * with a nested array of bean names that the present bean depends on.
 * @param contexts the set of ApplicationContexts
 * @return the JSON document
 */
protected String generateJson(Set<ConfigurableApplicationContext> contexts) {
	StringBuilder result = new StringBuilder("[\n");
	for (Iterator<ConfigurableApplicationContext> it = contexts.iterator(); it.hasNext();) {
		ConfigurableApplicationContext context = it.next();
		result.append("{\n\"context\": \"").append(context.getId()).append("\",\n");
		if (context.getParent() != null) {
			result.append("\"parent\": \"").append(context.getParent().getId()).append("\",\n");
		}
		else {
			result.append("\"parent\": null,\n");
		}
		result.append("\"beans\": [\n");
		ConfigurableListableBeanFactory bf = context.getBeanFactory();
		String[] beanNames = bf.getBeanDefinitionNames();
		boolean elementAppended = false;
		for (String beanName : beanNames) {
			BeanDefinition bd = bf.getBeanDefinition(beanName);
			if (isBeanEligible(beanName, bd, bf)) {
				if (elementAppended) {
					result.append(",\n");
				}
				result.append("{\n\"bean\": \"").append(beanName).append("\",\n");
				result.append("\"aliases\": ");
				appendArray(result, bf.getAliases(beanName));
				result.append(",\n");
				String scope = bd.getScope();
				if (!StringUtils.hasText(scope)) {
					scope = BeanDefinition.SCOPE_SINGLETON;
				}
				result.append("\"scope\": \"").append(scope).append("\",\n");
				Class<?> beanType = bf.getType(beanName);
				if (beanType != null) {
					result.append("\"type\": \"").append(beanType.getName()).append("\",\n");
				}
				else {
					result.append("\"type\": null,\n");
				}
				result.append("\"resource\": \"").append(getEscapedResourceDescription(bd)).append("\",\n");
				result.append("\"dependencies\": ");
				appendArray(result, bf.getDependenciesForBean(beanName));
				result.append("\n}");
				elementAppended = true;
			}
		}
		result.append("]\n");
		result.append("}");
		if (it.hasNext()) {
			result.append(",\n");
		}
	}
	result.append("]");
	return result.toString();
}
 
源代码9 项目: lams   文件: LiveBeansView.java
/**
 * Actually generate a JSON snapshot of the beans in the given ApplicationContexts.
 * <p>This implementation doesn't use any JSON parsing libraries in order to avoid
 * third-party library dependencies. It produces an array of context description
 * objects, each containing a context and parent attribute as well as a beans
 * attribute with nested bean description objects. Each bean object contains a
 * bean, scope, type and resource attribute, as well as a dependencies attribute
 * with a nested array of bean names that the present bean depends on.
 * @param contexts the set of ApplicationContexts
 * @return the JSON document
 */
protected String generateJson(Set<ConfigurableApplicationContext> contexts) {
	StringBuilder result = new StringBuilder("[\n");
	for (Iterator<ConfigurableApplicationContext> it = contexts.iterator(); it.hasNext();) {
		ConfigurableApplicationContext context = it.next();
		result.append("{\n\"context\": \"").append(context.getId()).append("\",\n");
		if (context.getParent() != null) {
			result.append("\"parent\": \"").append(context.getParent().getId()).append("\",\n");
		}
		else {
			result.append("\"parent\": null,\n");
		}
		result.append("\"beans\": [\n");
		ConfigurableListableBeanFactory bf = context.getBeanFactory();
		String[] beanNames = bf.getBeanDefinitionNames();
		boolean elementAppended = false;
		for (String beanName : beanNames) {
			BeanDefinition bd = bf.getBeanDefinition(beanName);
			if (isBeanEligible(beanName, bd, bf)) {
				if (elementAppended) {
					result.append(",\n");
				}
				result.append("{\n\"bean\": \"").append(beanName).append("\",\n");
				result.append("\"aliases\": ");
				appendArray(result, bf.getAliases(beanName));
				result.append(",\n");
				String scope = bd.getScope();
				if (!StringUtils.hasText(scope)) {
					scope = BeanDefinition.SCOPE_SINGLETON;
				}
				result.append("\"scope\": \"").append(scope).append("\",\n");
				Class<?> beanType = bf.getType(beanName);
				if (beanType != null) {
					result.append("\"type\": \"").append(beanType.getName()).append("\",\n");
				}
				else {
					result.append("\"type\": null,\n");
				}
				result.append("\"resource\": \"").append(getEscapedResourceDescription(bd)).append("\",\n");
				result.append("\"dependencies\": ");
				appendArray(result, bf.getDependenciesForBean(beanName));
				result.append("\n}");
				elementAppended = true;
			}
		}
		result.append("]\n");
		result.append("}");
		if (it.hasNext()) {
			result.append(",\n");
		}
	}
	result.append("]");
	return result.toString();
}
 
源代码10 项目: spring4-understanding   文件: LiveBeansView.java
/**
 * Actually generate a JSON snapshot of the beans in the given ApplicationContexts.
 * <p>This implementation doesn't use any JSON parsing libraries in order to avoid
 * third-party library dependencies. It produces an array of context description
 * objects, each containing a context and parent attribute as well as a beans
 * attribute with nested bean description objects. Each bean object contains a
 * bean, scope, type and resource attribute, as well as a dependencies attribute
 * with a nested array of bean names that the present bean depends on.
 * @param contexts the set of ApplicationContexts
 * @return the JSON document
 */
protected String generateJson(Set<ConfigurableApplicationContext> contexts) {
	StringBuilder result = new StringBuilder("[\n");
	for (Iterator<ConfigurableApplicationContext> it = contexts.iterator(); it.hasNext();) {
		ConfigurableApplicationContext context = it.next();
		result.append("{\n\"context\": \"").append(context.getId()).append("\",\n");
		if (context.getParent() != null) {
			result.append("\"parent\": \"").append(context.getParent().getId()).append("\",\n");
		}
		else {
			result.append("\"parent\": null,\n");
		}
		result.append("\"beans\": [\n");
		ConfigurableListableBeanFactory bf = context.getBeanFactory();
		String[] beanNames = bf.getBeanDefinitionNames();
		boolean elementAppended = false;
		for (String beanName : beanNames) {
			BeanDefinition bd = bf.getBeanDefinition(beanName);
			if (isBeanEligible(beanName, bd, bf)) {
				if (elementAppended) {
					result.append(",\n");
				}
				result.append("{\n\"bean\": \"").append(beanName).append("\",\n");
				String scope = bd.getScope();
				if (!StringUtils.hasText(scope)) {
					scope = BeanDefinition.SCOPE_SINGLETON;
				}
				result.append("\"scope\": \"").append(scope).append("\",\n");
				Class<?> beanType = bf.getType(beanName);
				if (beanType != null) {
					result.append("\"type\": \"").append(beanType.getName()).append("\",\n");
				}
				else {
					result.append("\"type\": null,\n");
				}
				result.append("\"resource\": \"").append(getEscapedResourceDescription(bd)).append("\",\n");
				result.append("\"dependencies\": [");
				String[] dependencies = bf.getDependenciesForBean(beanName);
				if (dependencies.length > 0) {
					result.append("\"");
				}
				result.append(StringUtils.arrayToDelimitedString(dependencies, "\", \""));
				if (dependencies.length > 0) {
					result.append("\"");
				}
				result.append("]\n}");
				elementAppended = true;
			}
		}
		result.append("]\n");
		result.append("}");
		if (it.hasNext()) {
			result.append(",\n");
		}
	}
	result.append("]");
	return result.toString();
}
 
源代码11 项目: sourcerer   文件: SourcererEventConfiguration.java
@Bean
@Lazy
@Scope(BeanDefinition.SCOPE_SINGLETON)
public EventRepository<T> getEventRepository() {
    return repositoryFactory.getEventRepository(eventType);
}
 
源代码12 项目: sourcerer   文件: EventStoreConfiguration.java
@Bean(name = "eventStoreStatus")
@Scope(BeanDefinition.SCOPE_SINGLETON)
public HealthIndicator getEventStoreHealthIndicator(final EventStore eventStore) {
    return new EventStoreHealthIndicator(eventStore);
}
 
源代码13 项目: sourcerer   文件: EventStoreConfiguration.java
@Bean
@Scope(BeanDefinition.SCOPE_SINGLETON)
public EsConnection getEventStoreConnection(
        @Value("${sourcerer.eventstore.hostname:127.0.0.1}") final String hostname,
        @Value("${sourcerer.eventstore.port:1113}") final int port,
        @Value("${sourcerer.eventstore.gossipPort:2113}") final int gossipPort,
        @Value("${sourcerer.eventstore.requireMaster:false}") final boolean requireMaster,
        @Value("${sourcerer.eventstore.useClusterDiscovery:false}")
        final boolean useClusterDiscovery) {
    ActorSystem system = ActorSystem.create();
    Settings defaultSettings = Settings.Default();
    Option<ClusterSettings> clusterSettings;

    if (useClusterDiscovery) {
        GossipSeedsOrDns clusterDns = GossipSeedsOrDns$.MODULE$.apply(hostname, gossipPort);
        clusterSettings = Option.apply(new ClusterSettings(
                clusterDns,
                FiniteDuration.apply(2, TimeUnit.SECONDS),
                10,
                FiniteDuration.apply(500, TimeUnit.MILLISECONDS),
                FiniteDuration.apply(1000, TimeUnit.MILLISECONDS),
                FiniteDuration.apply(1000, TimeUnit.MILLISECONDS)));
    } else {
        clusterSettings = Option.empty();
    }

    Settings settings = new Settings(
            new InetSocketAddress(hostname, port),
            defaultSettings.connectionTimeout(),
            -1,
            defaultSettings.reconnectionDelayMin(),
            defaultSettings.reconnectionDelayMax(),
            defaultSettings.defaultCredentials(),
            defaultSettings.heartbeatInterval(),
            defaultSettings.heartbeatTimeout(),
            defaultSettings.operationMaxRetries(),
            defaultSettings.operationTimeout(),
            defaultSettings.resolveLinkTos(),
            requireMaster,
            defaultSettings.readBatchSize(),
            defaultSettings.backpressure(),
            clusterSettings);
    return EsConnectionFactory.create(system, settings);
}
 
源代码14 项目: sourcerer   文件: EventStoreConfiguration.java
@Bean(name = "eventStoreStatus")
@Scope(BeanDefinition.SCOPE_SINGLETON)
public HealthIndicator getEventStoreHealthIndicator(final EsConnection connection) {
    return new EventStoreHealthIndicator(connection);
}
 
源代码15 项目: java_in_examples   文件: SpringBeanScopeTest.java
@Bean
@Scope(BeanDefinition.SCOPE_SINGLETON)
public SingletonClass2 getSingletonClass2(){
    return new SingletonClass2();
}
 
源代码16 项目: java_in_examples   文件: SpringBeanScopeTest.java
@Bean
@Scope(BeanDefinition.SCOPE_SINGLETON)
public SingletonClass2 getSingletonClass2(){
    return new SingletonClass2();
}