类 SpringContextResourceAdapter
- java.lang.Object
- org.springframework.jca.context.SpringContextResourceAdapter
- 所有已实现的接口:
ResourceAdapter
public class SpringContextResourceAdapter extends Object implements ResourceAdapter
JCA 1.7ResourceAdapterimplementation that loads a SpringApplicationContext, 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
WorkManagerTaskExecutoras 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
BootstrapContextmay also be accessed directly, through application components that implement theBootstrapContextAwareinterface. 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 Java EE ".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 https://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 entireconfig-propertysection 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!
字段概要
字段 修饰符和类型 字段 说明 static StringCONFIG_LOCATION_DELIMITERSAny number of these characters are considered delimiters between multiple context config paths in a single String value.static StringDEFAULT_CONTEXT_CONFIG_LOCATIONThe defaultapplicationContext.xmllocation.protected Loglogger
构造器概要
构造器 构造器 说明 SpringContextResourceAdapter()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected ConfigurableApplicationContextcreateApplicationContext(BootstrapContext bootstrapContext)Build a Spring ApplicationContext for the given JCA BootstrapContext.protected ConfigurableEnvironmentcreateEnvironment()Return a newStandardEnvironment.voidendpointActivation(MessageEndpointFactory messageEndpointFactory, ActivationSpec activationSpec)This implementation always throws a NotSupportedException.voidendpointDeactivation(MessageEndpointFactory messageEndpointFactory, ActivationSpec activationSpec)This implementation does nothing.booleanequals(Object other)protected StringgetContextConfigLocation()Return the specified context configuration files.XAResource[]getXAResources(ActivationSpec[] activationSpecs)This implementation always returnsnull.inthashCode()protected voidloadBeanDefinitions(BeanDefinitionRegistry registry, String[] configLocations)Load the bean definitions into the given registry, based on the specified configuration files.voidsetContextConfigLocation(String contextConfigLocation)Set the location of the context configuration files, within the resource adapter's deployment unit.voidstart(BootstrapContext bootstrapContext)This implementation loads a Spring ApplicationContext through thecreateApplicationContext(javax.resource.spi.BootstrapContext)template method.voidstop()This implementation closes the Spring ApplicationContext.
字段详细资料
CONFIG_LOCATION_DELIMITERS
public static final String CONFIG_LOCATION_DELIMITERS
Any number of these characters are considered delimiters between multiple context config paths in a single String value.
DEFAULT_CONTEXT_CONFIG_LOCATION
public static final String DEFAULT_CONTEXT_CONFIG_LOCATION
The defaultapplicationContext.xmllocation.- 另请参阅:
- 常量字段值
构造器详细资料
SpringContextResourceAdapter
public SpringContextResourceAdapter()
方法详细资料
setContextConfigLocation
public void setContextConfigLocation(String contextConfigLocation)
Set the location of the context configuration files, within the resource adapter's deployment unit. This can be a delimited String that consists of multiple resource location, separated by commas, semicolons, whitespace, or line breaks.This can be specified as "ContextConfigLocation" config property in the
ra.xmldeployment descriptor.The default is "classpath:META-INF/applicationContext.xml".
getContextConfigLocation
protected String getContextConfigLocation()
Return the specified context configuration files.
createEnvironment
protected ConfigurableEnvironment createEnvironment()
Return a newStandardEnvironment.Subclasses may override this method in order to supply a custom
ConfigurableEnvironmentimplementation.
start
public void start(BootstrapContext bootstrapContext) throws ResourceAdapterInternalException
This implementation loads a Spring ApplicationContext through thecreateApplicationContext(javax.resource.spi.BootstrapContext)template method.- 指定者:
start在接口中ResourceAdapter- 抛出:
ResourceAdapterInternalException
createApplicationContext
protected ConfigurableApplicationContext createApplicationContext(BootstrapContext bootstrapContext)
Build a Spring ApplicationContext for the given JCA BootstrapContext.The default implementation builds a
ResourceAdapterApplicationContextand delegates toloadBeanDefinitions(org.springframework.beans.factory.support.BeanDefinitionRegistry, java.lang.String[])for actually parsing the specified configuration files.- 参数:
bootstrapContext- this ResourceAdapter's BootstrapContext- 返回:
- the Spring ApplicationContext instance
loadBeanDefinitions
protected void loadBeanDefinitions(BeanDefinitionRegistry registry, String[] configLocations)
Load the bean definitions into the given registry, based on the specified configuration files.- 参数:
registry- the registry to load intoconfigLocations- the parsed config locations- 另请参阅:
setContextConfigLocation(java.lang.String)
stop
public void stop()
This implementation closes the Spring ApplicationContext.- 指定者:
stop在接口中ResourceAdapter
endpointActivation
public void endpointActivation(MessageEndpointFactory messageEndpointFactory, ActivationSpec activationSpec) throws ResourceException
This implementation always throws a NotSupportedException.- 指定者:
endpointActivation在接口中ResourceAdapter- 抛出:
ResourceException
endpointDeactivation
public void endpointDeactivation(MessageEndpointFactory messageEndpointFactory, ActivationSpec activationSpec)
This implementation does nothing.- 指定者:
endpointDeactivation在接口中ResourceAdapter
getXAResources
@Nullable public XAResource[] getXAResources(ActivationSpec[] activationSpecs) throws ResourceException
This implementation always returnsnull.- 指定者:
getXAResources在接口中ResourceAdapter- 抛出:
ResourceException