public class SpringObjectFactory extends ObjectFactory implements org.springframework.context.ApplicationContextAware
Simple implementation of the ObjectFactory that makes use of Spring's application context if one has been configured, before falling back on the default mechanism of instantiating a new class using the class name.
In order to use this class in your application, you will need to instantiate a copy of this class and set it as XWork's ObjectFactory before the xwork.xml file is parsed. In a servlet environment, this could be done using a ServletContextListener.
Modifier and Type | Field and Description |
---|---|
protected org.springframework.context.ApplicationContext |
appContext |
protected int |
autowireStrategy |
protected org.springframework.beans.factory.config.AutowireCapableBeanFactory |
autoWiringFactory |
Constructor and Description |
---|
SpringObjectFactory() |
Modifier and Type | Method and Description |
---|---|
Object |
autoWireBean(Object bean) |
Object |
autoWireBean(Object bean,
org.springframework.beans.factory.config.AutowireCapableBeanFactory autoWiringFactory) |
Object |
buildBean(Class clazz,
Map<String,Object> extraContext)
Build a generic Java object of the given type.
|
Object |
buildBean(String beanName,
Map<String,Object> extraContext,
boolean injectInternal)
Looks up beans using Spring's application context before falling back to the method defined in the
ObjectFactory . |
protected org.springframework.beans.factory.config.AutowireCapableBeanFactory |
findAutoWiringBeanFactory(org.springframework.context.ApplicationContext context)
If the given context is assignable to AutowireCapbleBeanFactory or contains a parent or a factory that is, then
set the autoWiringFactory appropriately.
|
int |
getAutowireStrategy() |
Class |
getClassInstance(String className)
Utility method to obtain the class matched to className.
|
boolean |
isNoArgConstructorRequired()
Allows for ObjectFactory implementations that support
Actions without no-arg constructors.
|
void |
setAlwaysRespectAutowireStrategy(boolean alwaysRespectAutowireStrategy)
Determines if the autowire strategy is always followed when creating beans
|
void |
setApplicationContext(org.springframework.context.ApplicationContext appContext)
Set the Spring ApplicationContext that should be used to look beans up with.
|
void |
setApplicationContextPath(String ctx) |
void |
setAutowireStrategy(int autowireStrategy)
Sets the autowiring strategy
|
void |
setEnableAopSupport(String enableAopSupport) |
void |
setUseClassCache(boolean useClassCache)
Enable / disable caching of classes loaded by Spring.
|
buildAction, buildBean, buildConverter, buildInterceptor, buildResult, buildUnknownHandler, buildValidator, injectInternalBeans, setActionFactory, setClassLoader, setContainer, setConverterFactory, setInterceptorFactory, setResultFactory, setUnknownHandlerFactory, setValidatorFactory
protected org.springframework.context.ApplicationContext appContext
protected org.springframework.beans.factory.config.AutowireCapableBeanFactory autoWiringFactory
protected int autowireStrategy
public void setApplicationContextPath(String ctx)
public void setEnableAopSupport(String enableAopSupport)
public void setApplicationContext(org.springframework.context.ApplicationContext appContext) throws org.springframework.beans.BeansException
setApplicationContext
in interface org.springframework.context.ApplicationContextAware
appContext
- The Spring ApplicationContext that should be used to look beans up with.org.springframework.beans.BeansException
public void setAutowireStrategy(int autowireStrategy)
autowireStrategy
- the autowire strategypublic int getAutowireStrategy()
protected org.springframework.beans.factory.config.AutowireCapableBeanFactory findAutoWiringBeanFactory(org.springframework.context.ApplicationContext context)
context
- the application contextpublic Object buildBean(String beanName, Map<String,Object> extraContext, boolean injectInternal) throws Exception
ObjectFactory
.buildBean
in class ObjectFactory
beanName
- The name of the bean to look up in the application contextextraContext
- additional context parametersinjectInternal
- true if inject internal beansException
- in case of any errorspublic Object buildBean(Class clazz, Map<String,Object> extraContext) throws Exception
ObjectFactory
buildBean
in class ObjectFactory
clazz
- class of beanextraContext
- additional context parametersException
- in case of any errorspublic Object autoWireBean(Object bean, org.springframework.beans.factory.config.AutowireCapableBeanFactory autoWiringFactory)
bean
- the bean to be autowiredautoWiringFactory
- the autowiring factorypublic Class getClassInstance(String className) throws ClassNotFoundException
ObjectFactory
getClassInstance
in class ObjectFactory
className
- The fully qualified name of the class to returnClassNotFoundException
- if class not found in classpathpublic boolean isNoArgConstructorRequired()
isNoArgConstructorRequired
in class ObjectFactory
public void setUseClassCache(boolean useClassCache)
useClassCache
- enable / disable class cachepublic void setAlwaysRespectAutowireStrategy(boolean alwaysRespectAutowireStrategy)
alwaysRespectAutowireStrategy
- True if the strategy is always usedCopyright © 2000–2020 Apache Software Foundation. All rights reserved.