org.springframework.beans.factory.config.CustomScopeConfigurer Java Examples

The following examples show how to use org.springframework.beans.factory.config.CustomScopeConfigurer. 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: TestConfig.java    From tutorials with MIT License 7 votes vote down vote up
@Bean
public CustomScopeConfigurer customScopeConfigurer() {
    CustomScopeConfigurer configurer = new CustomScopeConfigurer();
    configurer.addScope("session", new SimpleThreadScope());
    return configurer;
}
 
Example #2
Source File: ViewScopeDestructionCallbackIT.java    From joinfaces with Apache License 2.0 6 votes vote down vote up
@Test
public void testExpectedSpringBehaviour() throws NoSuchFieldException, IllegalAccessException {
	Field scopesField = CustomScopeConfigurer.class.getDeclaredField("scopes");
	scopesField.setAccessible(true);
	Map<String, org.springframework.beans.factory.config.Scope> scopes = (Map<String, org.springframework.beans.factory.config.Scope>) scopesField.get(this.testScopeConfigurer);
	TestConfig.TestScope testScope = (TestConfig.TestScope) scopes.get("test");

	BeanWithTwoDestructionCallbacks bean = this.applicationContext.getBean(BeanWithTwoDestructionCallbacks.class);

	assertThat(bean.destroyCalled).isFalse();
	assertThat(bean.preDestroyCalled).isFalse();

	assertThat(testScope.getBeans()).hasSize(1);
	assertThat(testScope.getCallbacks()).hasSize(1);

	//Only one destruction callback per bean
	List<Runnable> destructionCallbacks = testScope.getCallbacks().get("beanWithTwoDestructionCallbacks");
	assertThat(destructionCallbacks).hasSize(1);

	//The one destruction callback calls all destroy-methods
	destructionCallbacks.get(0).run();
	assertThat(bean.preDestroyCalled).isTrue();
	assertThat(bean.destroyCalled).isTrue();
}
 
Example #3
Source File: ViewScopeDestructionCallbackIT.java    From joinfaces with Apache License 2.0 5 votes vote down vote up
@Bean
public static CustomScopeConfigurer testScopeConfigurer() {
	CustomScopeConfigurer customScopeConfigurer = new CustomScopeConfigurer();

	customScopeConfigurer.addScope("test", new TestScope());

	return customScopeConfigurer;
}
 
Example #4
Source File: AppConfig.java    From spring4-sandbox with Apache License 2.0 5 votes vote down vote up
@Bean
public static CustomScopeConfigurer customScopeConfigurer() {
    Map<String, Object> scopes = new HashMap<>();
    scopes.put("view", new ViewScope());

    CustomScopeConfigurer bean = new CustomScopeConfigurer();
    bean.setScopes(scopes);

    return bean;
}
 
Example #5
Source File: Application.java    From sitemonitoring-production with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Bean
public static CustomScopeConfigurer viewScopeConfigurer() {
    CustomScopeConfigurer customScopeConfigurer = new CustomScopeConfigurer();
    Map scopes = new HashMap();
    scopes.put("view", new ViewScope());
    customScopeConfigurer.setScopes(scopes);
    return customScopeConfigurer;
}
 
Example #6
Source File: Main.java    From JSF-on-Spring-Boot with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("serial")
@Bean public org.springframework.beans.factory.config.CustomScopeConfigurer customScopeConfigurer(){
   	CustomScopeConfigurer csc = new CustomScopeConfigurer();
   	csc.setScopes(new HashMap<String, Object>() {{
   		put("view", new com.liferay.faces.demos.spring.ViewScope());
   	}});
   	return csc;
   }
 
Example #7
Source File: TenantConfiguration.java    From fiware-cepheus with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Declare the "tenant" scope.
 */
@Bean
public static CustomScopeConfigurer customScopeConfigurer (TenantScope tenantScope) {
    CustomScopeConfigurer configurer = new CustomScopeConfigurer ();
    configurer.addScope("tenant", tenantScope);
    return configurer;
}
 
Example #8
Source File: DolphinPlatformSpringTestBootstrap.java    From dolphin-platform with Apache License 2.0 5 votes vote down vote up
@Bean(name = "customScopeConfigurer")
public static CustomScopeConfigurer createClientScope(final ClientSession clientSession) {
    Assert.requireNonNull(clientSession, "clientSession");
    CustomScopeConfigurer configurer = new CustomScopeConfigurer();
    configurer.addScope(ClientScopeImpl.CLIENT_SCOPE, new TestClientScope(clientSession));
    return configurer;
}
 
Example #9
Source File: Application.java    From sitemonitoring-production with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Bean
public static CustomScopeConfigurer viewScopeConfigurer() {
    CustomScopeConfigurer customScopeConfigurer = new CustomScopeConfigurer();
    Map scopes = new HashMap();
    scopes.put("view", new ViewScope());
    customScopeConfigurer.setScopes(scopes);
    return customScopeConfigurer;
}
 
Example #10
Source File: ViewScopeAutoConfiguration.java    From joinfaces with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnProperty(value = "joinfaces.view-scope.enabled", havingValue = "true", matchIfMissing = true)
public static CustomScopeConfigurer viewScopeConfigurer() {
	CustomScopeConfigurer customScopeConfigurer = new CustomScopeConfigurer();
	customScopeConfigurer.addScope(ViewScope.SCOPE_VIEW, new ViewScope());
	return customScopeConfigurer;
}
 
Example #11
Source File: WebSocketMessageBrokerConfigurationSupport.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Bean
public static CustomScopeConfigurer webSocketScopeConfigurer() {
	CustomScopeConfigurer configurer = new CustomScopeConfigurer();
	configurer.addScope("websocket", new SimpSessionScope());
	return configurer;
}
 
Example #12
Source File: MessageBrokerBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public BeanDefinition parse(Element element, ParserContext context) {

	Object source = context.extractSource(element);
	CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
	context.pushContainingComponent(compDefinition);

	Element channelElem = DomUtils.getChildElementByTagName(element, "client-inbound-channel");
	RuntimeBeanReference inChannel = getMessageChannel("clientInboundChannel", channelElem, context, source);

	channelElem = DomUtils.getChildElementByTagName(element, "client-outbound-channel");
	RuntimeBeanReference outChannel = getMessageChannel("clientOutboundChannel", channelElem, context, source);

	channelElem = DomUtils.getChildElementByTagName(element, "broker-channel");
	RuntimeBeanReference brokerChannel = getMessageChannel("brokerChannel", channelElem, context, source);

	RuntimeBeanReference userRegistry = registerUserRegistry(element, context, source);
	Object userDestHandler = registerUserDestHandler(element, userRegistry, inChannel, brokerChannel, context, source);

	RuntimeBeanReference converter = registerMessageConverter(element, context, source);
	RuntimeBeanReference template = registerMessagingTemplate(element, brokerChannel, converter, context, source);
	registerAnnotationMethodMessageHandler(element, inChannel, outChannel,converter, template, context, source);

	RootBeanDefinition broker = registerMessageBroker(element, inChannel, outChannel, brokerChannel,
			userDestHandler, template, userRegistry, context, source);

	// WebSocket and sub-protocol handling

	ManagedMap<String, Object> urlMap = registerHandlerMapping(element, context, source);
	RuntimeBeanReference stompHandler = registerStompHandler(element, inChannel, outChannel, context, source);
	for (Element endpointElem : DomUtils.getChildElementsByTagName(element, "stomp-endpoint")) {
		RuntimeBeanReference requestHandler = registerRequestHandler(endpointElem, stompHandler, context, source);
		String pathAttribute = endpointElem.getAttribute("path");
		Assert.state(StringUtils.hasText(pathAttribute), "Invalid <stomp-endpoint> (no path mapping)");
		List<String> paths = Arrays.asList(StringUtils.tokenizeToStringArray(pathAttribute, ","));
		for (String path : paths) {
			path = path.trim();
			Assert.state(StringUtils.hasText(path), "Invalid <stomp-endpoint> path attribute: " + pathAttribute);
			if (DomUtils.getChildElementByTagName(endpointElem, "sockjs") != null) {
				path = path.endsWith("/") ? path + "**" : path + "/**";
			}
			urlMap.put(path, requestHandler);
		}
	}

	Map<String, Object> scopeMap = Collections.<String, Object>singletonMap("websocket", new SimpSessionScope());
	RootBeanDefinition scopeConfigurer = new RootBeanDefinition(CustomScopeConfigurer.class);
	scopeConfigurer.getPropertyValues().add("scopes", scopeMap);
	registerBeanDefByName("webSocketScopeConfigurer", scopeConfigurer, context, source);

	registerWebSocketMessageBrokerStats(broker, inChannel, outChannel, context, source);

	context.popAndRegisterContainingComponent();
	return null;
}
 
Example #13
Source File: SpringBeanFactory.java    From dolphin-platform with Apache License 2.0 4 votes vote down vote up
@Bean(name = "customScopeConfigurer")
public static CustomScopeConfigurer createClientScope() {
    final CustomScopeConfigurer configurer = new CustomScopeConfigurer();
    configurer.addScope(ClientScopeImpl.CLIENT_SCOPE, new ClientScopeImpl());
    return configurer;
}
 
Example #14
Source File: WebSocketMessageBrokerConfigurationSupport.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Bean
public static CustomScopeConfigurer webSocketScopeConfigurer() {
	CustomScopeConfigurer configurer = new CustomScopeConfigurer();
	configurer.addScope("websocket", new SimpSessionScope());
	return configurer;
}
 
Example #15
Source File: SpringConfiguration.java    From prebid-server-java with Apache License 2.0 4 votes vote down vote up
@Bean
static CustomScopeConfigurer customScopeConfigurer() {
    final CustomScopeConfigurer configurer = new CustomScopeConfigurer();
    configurer.setScopes(Collections.singletonMap(VertxContextScope.NAME, new VertxContextScope()));
    return configurer;
}
 
Example #16
Source File: MessageBrokerBeanDefinitionParser.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public BeanDefinition parse(Element element, ParserContext context) {
	Object source = context.extractSource(element);
	CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
	context.pushContainingComponent(compDefinition);

	Element channelElem = DomUtils.getChildElementByTagName(element, "client-inbound-channel");
	RuntimeBeanReference inChannel = getMessageChannel("clientInboundChannel", channelElem, context, source);

	channelElem = DomUtils.getChildElementByTagName(element, "client-outbound-channel");
	RuntimeBeanReference outChannel = getMessageChannel("clientOutboundChannel", channelElem, context, source);

	channelElem = DomUtils.getChildElementByTagName(element, "broker-channel");
	RuntimeBeanReference brokerChannel = getMessageChannel("brokerChannel", channelElem, context, source);

	RuntimeBeanReference userRegistry = registerUserRegistry(element, context, source);
	Object userDestHandler = registerUserDestHandler(element, userRegistry, inChannel, brokerChannel, context, source);

	RuntimeBeanReference converter = registerMessageConverter(element, context, source);
	RuntimeBeanReference template = registerMessagingTemplate(element, brokerChannel, converter, context, source);
	registerAnnotationMethodMessageHandler(element, inChannel, outChannel,converter, template, context, source);

	RootBeanDefinition broker = registerMessageBroker(element, inChannel, outChannel, brokerChannel,
			userDestHandler, template, userRegistry, context, source);

	// WebSocket and sub-protocol handling

	ManagedMap<String, Object> urlMap = registerHandlerMapping(element, context, source);
	RuntimeBeanReference stompHandler = registerStompHandler(element, inChannel, outChannel, context, source);
	for (Element endpointElem : DomUtils.getChildElementsByTagName(element, "stomp-endpoint")) {
		RuntimeBeanReference requestHandler = registerRequestHandler(endpointElem, stompHandler, context, source);
		String pathAttribute = endpointElem.getAttribute("path");
		Assert.hasText(pathAttribute, "Invalid <stomp-endpoint> (no path mapping)");
		for (String path : StringUtils.tokenizeToStringArray(pathAttribute, ",")) {
			path = path.trim();
			Assert.hasText(path, () -> "Invalid <stomp-endpoint> path attribute: " + pathAttribute);
			if (DomUtils.getChildElementByTagName(endpointElem, "sockjs") != null) {
				path = (path.endsWith("/") ? path + "**" : path + "/**");
			}
			urlMap.put(path, requestHandler);
		}
	}

	Map<String, Object> scopeMap = Collections.singletonMap("websocket", new SimpSessionScope());
	RootBeanDefinition scopeConfigurer = new RootBeanDefinition(CustomScopeConfigurer.class);
	scopeConfigurer.getPropertyValues().add("scopes", scopeMap);
	registerBeanDefByName("webSocketScopeConfigurer", scopeConfigurer, context, source);

	registerWebSocketMessageBrokerStats(broker, inChannel, outChannel, context, source);

	context.popAndRegisterContainingComponent();
	return null;
}
 
Example #17
Source File: WebSocketMessageBrokerConfigurationSupport.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Bean
public static CustomScopeConfigurer webSocketScopeConfigurer() {
	CustomScopeConfigurer configurer = new CustomScopeConfigurer();
	configurer.addScope("websocket", new SimpSessionScope());
	return configurer;
}
 
Example #18
Source File: MessageBrokerBeanDefinitionParser.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public BeanDefinition parse(Element element, ParserContext context) {
	Object source = context.extractSource(element);
	CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
	context.pushContainingComponent(compDefinition);

	Element channelElem = DomUtils.getChildElementByTagName(element, "client-inbound-channel");
	RuntimeBeanReference inChannel = getMessageChannel("clientInboundChannel", channelElem, context, source);

	channelElem = DomUtils.getChildElementByTagName(element, "client-outbound-channel");
	RuntimeBeanReference outChannel = getMessageChannel("clientOutboundChannel", channelElem, context, source);

	channelElem = DomUtils.getChildElementByTagName(element, "broker-channel");
	RuntimeBeanReference brokerChannel = getMessageChannel("brokerChannel", channelElem, context, source);

	RuntimeBeanReference userRegistry = registerUserRegistry(element, context, source);
	Object userDestHandler = registerUserDestHandler(element, userRegistry, inChannel, brokerChannel, context, source);

	RuntimeBeanReference converter = registerMessageConverter(element, context, source);
	RuntimeBeanReference template = registerMessagingTemplate(element, brokerChannel, converter, context, source);
	registerAnnotationMethodMessageHandler(element, inChannel, outChannel,converter, template, context, source);

	RootBeanDefinition broker = registerMessageBroker(element, inChannel, outChannel, brokerChannel,
			userDestHandler, template, userRegistry, context, source);

	// WebSocket and sub-protocol handling

	ManagedMap<String, Object> urlMap = registerHandlerMapping(element, context, source);
	RuntimeBeanReference stompHandler = registerStompHandler(element, inChannel, outChannel, context, source);
	for (Element endpointElem : DomUtils.getChildElementsByTagName(element, "stomp-endpoint")) {
		RuntimeBeanReference requestHandler = registerRequestHandler(endpointElem, stompHandler, context, source);
		String pathAttribute = endpointElem.getAttribute("path");
		Assert.hasText(pathAttribute, "Invalid <stomp-endpoint> (no path mapping)");
		for (String path : StringUtils.tokenizeToStringArray(pathAttribute, ",")) {
			path = path.trim();
			Assert.hasText(path, () -> "Invalid <stomp-endpoint> path attribute: " + pathAttribute);
			if (DomUtils.getChildElementByTagName(endpointElem, "sockjs") != null) {
				path = (path.endsWith("/") ? path + "**" : path + "/**");
			}
			urlMap.put(path, requestHandler);
		}
	}

	Map<String, Object> scopeMap = Collections.singletonMap("websocket", new SimpSessionScope());
	RootBeanDefinition scopeConfigurer = new RootBeanDefinition(CustomScopeConfigurer.class);
	scopeConfigurer.getPropertyValues().add("scopes", scopeMap);
	registerBeanDefByName("webSocketScopeConfigurer", scopeConfigurer, context, source);

	registerWebSocketMessageBrokerStats(broker, inChannel, outChannel, context, source);

	context.popAndRegisterContainingComponent();
	return null;
}