Package com.oracle.coherence.spring
Class SpringNamespaceHandler
- java.lang.Object
-
- com.tangosol.config.xml.AbstractNamespaceHandler
-
- com.oracle.coherence.spring.SpringNamespaceHandler
-
- All Implemented Interfaces:
com.tangosol.config.xml.NamespaceHandler
public class SpringNamespaceHandler extends com.tangosol.config.xml.AbstractNamespaceHandler
TheSpringNamespaceHandler
provides the ability to reference Spring beans in a cache configuration file. In cases where a cache configuration needs to specify an externally provided user class via a <class-scheme> or <instance> element, this namespace handler can provide a Spring bean from a BeanFactory.In order to use this handler in a cache configuration file, the handler must be declared. This is done via the following declaration:
xmlns:spring="class://com.oracle.coherence.spring.SpringNamespaceHandler"
To guard against invalid configuration, the XSD (coherence-spring-config.xsd) that corresponds to this namespace handler can also be referenced.Here is a complete example:
<cache-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.oracle.com/coherence/coherence-cache-config" xmlns:spring="class://com.oracle.coherence.spring.SpringNamespaceHandler" xsi:schemaLocation="http://xmlns.oracle.com/coherence/coherence-cache-config coherence-cache-config.xsd class://com.oracle.coherence.spring.SpringNamespaceHandler coherence-spring-config.xsd">
To specify a bean, use the <bean> and <bean-name> elements under <class-scheme> or <instance> elements:<class-scheme> <spring:bean> <spring:bean-name>listener</spring:bean-name> </spring:bean> </class-scheme>
Cache configuration properties (including cache configuration macros) can be injected into a bean using two possible mechanisms: push or pull. The push mechanism allows the runtime macro value to be injected into the bean by thisNamespaceHandler
such as:<spring:bean> <spring:bean-name>listener</spring:bean-name> <spring:property name="backingMapManagerContext">{manager-context}</spring:property> </spring:bean>
The pull mechanism allows for cache configuration properties to be referenced in the Spring application context file such as:<bean id="listener" class="foo.BML" lazy-init="true"> <property name="backingMapManagerContext" value="#{manager-context}"/> </bean>
A bean factory that will provide the Spring beans can be specified in two ways:1. Specify an application context in the cache configuration file:
<spring:bean-factory> <spring:application-context-uri>application-context.xml</spring:application-context-uri> </spring:bean-factory>
Similar to a cache configuration file, the application context file will be loaded either via the file system or the classpath. URLs are supported.2. Specify a bean factory as a resource:
A Spring bean factory can be manually registered as a resource in the following manner:
ConfigurableCacheFactory factory = CacheFactory.getCacheFactoryBuilder(). getConfigurableCacheFactory(...); factory.getResourceRegistry().registerResource(BeanFactory.class, // type factoryName, // resource name factory, // factory reference null); // optional ResourceLifecycleObserver
If a resource name other than the fully-qualified-class-name of the BeanFactory is specified, that name can be referenced in the bean element:<spring:bean> <spring:factory-name>custom-factory</spring:factory-name> <spring:bean-name>listener</spring:bean-name> </spring:bean>
Copyright (c) 2013-2015. All Rights Reserved. Oracle Corporation.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.- Author:
- Patrick Peralta, Brian Oliver
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SpringNamespaceHandler.PropertyProcessor
Implementation ofElementProcessor
that creates an instance ofParameter
containing a property name and value to be injected into a Spring bean.static class
SpringNamespaceHandler.SpringBeanBuilder
Implementation ofParameterizedBuilder
that "realizes" a named bean from a SpringBeanFactory
.static class
SpringNamespaceHandler.SpringBeanFactoryBuilder
Implementation ofParameterizedBuilder
that "realizes" an instance ofBeanFactory
based on a provided Spring application context uri.
-
Constructor Summary
Constructors Constructor Description SpringNamespaceHandler()
Construct aSpringNamespaceHandler
.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description protected static String
getFactoryNameAsString(Class<?> factoryClass, com.tangosol.config.expression.Expression<String> exprFactoryName, com.tangosol.config.expression.ParameterResolver resolver)
Return the factory name produced by the provided expression, or the name of the factory class if the expression is null.-
Methods inherited from class com.tangosol.config.xml.AbstractNamespaceHandler
getAttributeProcessor, getAttributeProcessor, getDocumentPreprocessor, getElementProcessor, getElementProcessor, onEndNamespace, onStartNamespace, onUnknownAttribute, onUnknownElement, registerAttributeType, registerElementType, registerProcessor, registerProcessor, registerProcessor, setDocumentPreprocessor
-
-
-
-
Constructor Detail
-
SpringNamespaceHandler
public SpringNamespaceHandler()
Construct aSpringNamespaceHandler
.
-
-
Method Detail
-
getFactoryNameAsString
protected static String getFactoryNameAsString(Class<?> factoryClass, com.tangosol.config.expression.Expression<String> exprFactoryName, com.tangosol.config.expression.ParameterResolver resolver)
Return the factory name produced by the provided expression, or the name of the factory class if the expression is null.- Parameters:
factoryClass
- theClass
of the factory (this will be used if no factory name was specified)exprFactoryName
- the expression containing theBeanFactory
nameresolver
- theParameterResolver
to use for resolving factory names- Returns:
- factory name for the
BeanFactory
-
-