Package org.apache.struts2.spring
Class SpringObjectFactory
java.lang.Object
org.apache.struts2.ObjectFactory
org.apache.struts2.spring.SpringObjectFactory
- All Implemented Interfaces:
- Serializable,- org.springframework.beans.factory.Aware,- org.springframework.context.ApplicationContextAware
- Direct Known Subclasses:
- SpringProxyableObjectFactory,- StrutsSpringObjectFactory
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.
- Author:
- Simon Stewart (sms@lateral.net)
- See Also:
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected org.springframework.context.ApplicationContextprotected intprotected org.springframework.beans.factory.config.AutowireCapableBeanFactory
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionautoWireBean(Object bean) autoWireBean(Object bean, org.springframework.beans.factory.config.AutowireCapableBeanFactory autoWiringFactory) Looks up beans using Spring's application context before falling back to the method defined in theObjectFactory.protected org.springframework.beans.factory.config.AutowireCapableBeanFactoryfindAutoWiringBeanFactory(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.intgetClassInstance(String className) booleanAllows for ObjectFactory implementations that support Actions without no-arg constructors.voidsetAlwaysRespectAutowireStrategy(boolean alwaysRespectAutowireStrategy) Determines if the autowire strategy is always followed when creating beansvoidsetApplicationContext(org.springframework.context.ApplicationContext appContext) Set the Spring ApplicationContext that should be used to look beans up with.voidvoidsetAutowireStrategy(int autowireStrategy) Sets the autowiring strategyvoidsetEnableAopSupport(String enableAopSupport) voidsetUseClassCache(boolean useClassCache) Enable / disable caching of classes loaded by Spring.Methods inherited from class org.apache.struts2.ObjectFactorybuildAction, buildBean, buildConverter, buildInterceptor, buildResult, buildUnknownHandler, buildValidator, injectInternalBeans, setActionFactory, setClassLoader, setContainer, setConverterFactory, setInterceptorFactory, setResultFactory, setUnknownHandlerFactory, setValidatorFactory
- 
Field Details- 
appContextprotected org.springframework.context.ApplicationContext appContext
- 
autoWiringFactoryprotected org.springframework.beans.factory.config.AutowireCapableBeanFactory autoWiringFactory
- 
autowireStrategyprotected int autowireStrategy
 
- 
- 
Constructor Details- 
SpringObjectFactorypublic SpringObjectFactory()
 
- 
- 
Method Details- 
setApplicationContextPath
- 
setEnableAopSupport
- 
setApplicationContextpublic void setApplicationContext(org.springframework.context.ApplicationContext appContext) throws org.springframework.beans.BeansException Set the Spring ApplicationContext that should be used to look beans up with.- Specified by:
- setApplicationContextin interface- org.springframework.context.ApplicationContextAware
- Parameters:
- appContext- The Spring ApplicationContext that should be used to look beans up with.
- Throws:
- org.springframework.beans.BeansException
 
- 
setAutowireStrategypublic void setAutowireStrategy(int autowireStrategy) Sets the autowiring strategy- Parameters:
- autowireStrategy- the autowire strategy
 
- 
getAutowireStrategypublic int getAutowireStrategy()
- 
findAutoWiringBeanFactoryprotected 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.- Parameters:
- context- the application context
- Returns:
- the bean factory
 
- 
buildBeanpublic Object buildBean(String beanName, Map<String, Object> extraContext, boolean injectInternal) throws ExceptionLooks up beans using Spring's application context before falling back to the method defined in theObjectFactory.- Overrides:
- buildBeanin class- ObjectFactory
- Parameters:
- beanName- The name of the bean to look up in the application context
- extraContext- additional context parameters
- Returns:
- A bean from Spring or the result of calling the overridden method.
- Throws:
- Exception- in case of any errors
 
- 
buildBean- Overrides:
- buildBeanin class- ObjectFactory
- Parameters:
- clazz- class of bean
- extraContext- additional context parameters
- Returns:
- bean
- Throws:
- Exception- in case of any errors
 
- 
autoWireBean
- 
autoWireBeanpublic Object autoWireBean(Object bean, org.springframework.beans.factory.config.AutowireCapableBeanFactory autoWiringFactory) - Parameters:
- bean- the bean to be autowired
- autoWiringFactory- the autowiring factory
- Returns:
- bean
 
- 
getClassInstance- Overrides:
- getClassInstancein class- ObjectFactory
- Throws:
- ClassNotFoundException
 
- 
isNoArgConstructorRequiredpublic boolean isNoArgConstructorRequired()Allows for ObjectFactory implementations that support Actions without no-arg constructors.- Overrides:
- isNoArgConstructorRequiredin class- ObjectFactory
- Returns:
- false
 
- 
setUseClassCachepublic void setUseClassCache(boolean useClassCache) Enable / disable caching of classes loaded by Spring.- Parameters:
- useClassCache- enable / disable class cache
 
- 
setAlwaysRespectAutowireStrategypublic void setAlwaysRespectAutowireStrategy(boolean alwaysRespectAutowireStrategy) Determines if the autowire strategy is always followed when creating beans- Parameters:
- alwaysRespectAutowireStrategy- True if the strategy is always used
 
 
-