Java Code Examples for org.springframework.beans.factory.config.BeanDefinition#SCOPE_SINGLETON
The following examples show how to use
org.springframework.beans.factory.config.BeanDefinition#SCOPE_SINGLETON .
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: SourcererEventConfiguration.java From sourcerer with MIT License | 5 votes |
@Bean @Lazy @Scope(BeanDefinition.SCOPE_SINGLETON) EventSubscriptionFactory<T> getEventSubscriptionFactory( final EventRepository<T> eventRepository) { return new DefaultEventSubscriptionFactory<>(eventRepository); }
Example 2
Source File: SourcererCommandConfiguration.java From sourcerer with MIT License | 5 votes |
@Bean @Lazy @Scope(BeanDefinition.SCOPE_SINGLETON) public AggregateRepository<TState, TEvent> getAggregateRepository( final EventRepository<TEvent> eventRepository) { return new DefaultAggregateRepository<>(eventRepository, projection, this::resolveType); }
Example 3
Source File: SourcererCommandConfiguration.java From sourcerer with MIT License | 5 votes |
@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); }
Example 4
Source File: EventStoreConfiguration.java From sourcerer with MIT License | 5 votes |
@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(); }
Example 5
Source File: EventStoreConfiguration.java From sourcerer with MIT License | 5 votes |
@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()); }
Example 6
Source File: EventStoreConfiguration.java From sourcerer with MIT License | 5 votes |
@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()); }
Example 7
Source File: LiveBeansView.java From spring-analysis-note with MIT License | 4 votes |
/** * 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(); }
Example 8
Source File: LiveBeansView.java From java-technology-stack with MIT License | 4 votes |
/** * 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(); }
Example 9
Source File: LiveBeansView.java From lams with GNU General Public License v2.0 | 4 votes |
/** * 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(); }
Example 10
Source File: LiveBeansView.java From spring4-understanding with Apache License 2.0 | 4 votes |
/** * 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(); }
Example 11
Source File: SourcererEventConfiguration.java From sourcerer with MIT License | 4 votes |
@Bean @Lazy @Scope(BeanDefinition.SCOPE_SINGLETON) public EventRepository<T> getEventRepository() { return repositoryFactory.getEventRepository(eventType); }
Example 12
Source File: EventStoreConfiguration.java From sourcerer with MIT License | 4 votes |
@Bean(name = "eventStoreStatus") @Scope(BeanDefinition.SCOPE_SINGLETON) public HealthIndicator getEventStoreHealthIndicator(final EventStore eventStore) { return new EventStoreHealthIndicator(eventStore); }
Example 13
Source File: EventStoreConfiguration.java From sourcerer with MIT License | 4 votes |
@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); }
Example 14
Source File: EventStoreConfiguration.java From sourcerer with MIT License | 4 votes |
@Bean(name = "eventStoreStatus") @Scope(BeanDefinition.SCOPE_SINGLETON) public HealthIndicator getEventStoreHealthIndicator(final EsConnection connection) { return new EventStoreHealthIndicator(connection); }
Example 15
Source File: SpringBeanScopeTest.java From java_in_examples with Apache License 2.0 | 4 votes |
@Bean @Scope(BeanDefinition.SCOPE_SINGLETON) public SingletonClass2 getSingletonClass2(){ return new SingletonClass2(); }
Example 16
Source File: SpringBeanScopeTest.java From java_in_examples with Apache License 2.0 | 4 votes |
@Bean @Scope(BeanDefinition.SCOPE_SINGLETON) public SingletonClass2 getSingletonClass2(){ return new SingletonClass2(); }