|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.jca.context.SpringContextResourceAdapter
public class SpringContextResourceAdapter
JCA 1.5 ResourceAdapter
implementation
that loads a Spring ApplicationContext
,
starting and stopping Spring-managed beans as part of the ResourceAdapter's
lifecycle.
Ideal for application contexts that do not need any HTTP entry points but rather just consist of message endpoints and scheduled jobs etc. Beans in such a context may use application server resources such as the JTA transaction manager and JNDI-bound JDBC DataSources and JMS ConnectionFactory instances, and may also register with the platform's JMX server - all through Spring's standard transaction management and JNDI and JMX support facilities.
If the need for scheduling asynchronous work arises, consider using
Spring's WorkManagerTaskExecutor
as a standard bean definition, to be injected into application beans
through dependency injection. This WorkManagerTaskExecutor will automatically
use the JCA WorkManager from the BootstrapContext that has been provided
to this ResourceAdapter.
The JCA BootstrapContext
may also be
accessed directly, through application components that implement the
BootstrapContextAware
interface. When deployed using this
ResourceAdapter, the BootstrapContext is guaranteed to be passed on
to such components.
This ResourceAdapter is to be defined in a "META-INF/ra.xml" file within a J2EE ".rar" deployment unit like as follows:
<?xml version="1.0" encoding="UTF-8"?> <connector xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/connector_1_5.xsd" version="1.5"> <vendor-name>Spring Framework</vendor-name> <eis-type>Spring Connector</eis-type> <resourceadapter-version>1.0</resourceadapter-version> <resourceadapter> <resourceadapter-class>org.springframework.jca.context.SpringContextResourceAdapter</resourceadapter-class> <config-property> <config-property-name>ContextConfigLocation</config-property-name> <config-property-type>java.lang.String</config-property-type> <config-property-value>META-INF/applicationContext.xml</config-property-value> </config-property> </resourceadapter> </connector>Note that "META-INF/applicationContext.xml" is the default context config location, so it doesn't have to specified unless you intend to specify different/additional config files. So in the default case, you may remove the entire
config-property
section above.
For simple deployment needs, all you need to do is the following: Package all application classes into a RAR file (which is just a standard JAR file with a different file extension), add all required library jars into the root of the RAR archive, add a "META-INF/ra.xml" deployment descriptor as shown above as well as the corresponding Spring XML bean definition file(s) (typically "META-INF/applicationContext.xml"), and drop the resulting RAR file into your application server's deployment directory!
setContextConfigLocation(java.lang.String)
,
loadBeanDefinitions(org.springframework.beans.factory.support.BeanDefinitionRegistry, java.lang.String[])
,
ResourceAdapterApplicationContext
Field Summary | |
---|---|
static String |
CONFIG_LOCATION_DELIMITERS
Any number of these characters are considered delimiters between multiple context config paths in a single String value. |
static String |
DEFAULT_CONTEXT_CONFIG_LOCATION
|
protected Log |
logger
|
Constructor Summary | |
---|---|
SpringContextResourceAdapter()
|
Method Summary | |
---|---|
protected ConfigurableApplicationContext |
createApplicationContext(BootstrapContext bootstrapContext)
Build a Spring ApplicationContext for the given JCA BootstrapContext. |
void |
endpointActivation(MessageEndpointFactory messageEndpointFactory,
ActivationSpec activationSpec)
This implementation always throws a NotSupportedException. |
void |
endpointDeactivation(MessageEndpointFactory messageEndpointFactory,
ActivationSpec activationSpec)
This implementation does nothing. |
protected String |
getContextConfigLocation()
Return the specified context configuration files. |
XAResource[] |
getXAResources(ActivationSpec[] activationSpecs)
This implementation always returns null . |
protected void |
loadBeanDefinitions(BeanDefinitionRegistry registry,
String[] configLocations)
Load the bean definitions into the given registry, based on the specified configuration files. |
void |
setContextConfigLocation(String contextConfigLocation)
Set the location of the context configuration files, within the resource adapter's deployment unit. |
void |
start(BootstrapContext bootstrapContext)
This implementation loads a Spring ApplicationContext through the createApplicationContext(javax.resource.spi.BootstrapContext) template method. |
void |
stop()
This implementation closes the Spring ApplicationContext. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String CONFIG_LOCATION_DELIMITERS
setContextConfigLocation(java.lang.String)
,
Constant Field Valuespublic static final String DEFAULT_CONTEXT_CONFIG_LOCATION
protected final Log logger
Constructor Detail |
---|
public SpringContextResourceAdapter()
Method Detail |
---|
public void setContextConfigLocation(String contextConfigLocation)
This can be specified as "ContextConfigLocation" config
property in the ra.xml
deployment descriptor.
The default is "classpath:META-INF/applicationContext.xml".
protected String getContextConfigLocation()
public void start(BootstrapContext bootstrapContext) throws ResourceAdapterInternalException
createApplicationContext(javax.resource.spi.BootstrapContext)
template method.
start
in interface ResourceAdapter
ResourceAdapterInternalException
protected ConfigurableApplicationContext createApplicationContext(BootstrapContext bootstrapContext)
The default implementation builds a ResourceAdapterApplicationContext
and delegates to loadBeanDefinitions(org.springframework.beans.factory.support.BeanDefinitionRegistry, java.lang.String[])
for actually parsing the
specified configuration files.
bootstrapContext
- this ResourceAdapter's BootstrapContext
protected void loadBeanDefinitions(BeanDefinitionRegistry registry, String[] configLocations)
registry
- the registry to load intoconfigLocations
- the parsed config locationssetContextConfigLocation(java.lang.String)
public void stop()
stop
in interface ResourceAdapter
public void endpointActivation(MessageEndpointFactory messageEndpointFactory, ActivationSpec activationSpec) throws ResourceException
endpointActivation
in interface ResourceAdapter
ResourceException
public void endpointDeactivation(MessageEndpointFactory messageEndpointFactory, ActivationSpec activationSpec)
endpointDeactivation
in interface ResourceAdapter
public XAResource[] getXAResources(ActivationSpec[] activationSpecs) throws ResourceException
null
.
getXAResources
in interface ResourceAdapter
ResourceException
|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |