Class AnnotProxyFieldValueFactory
- java.lang.Object
-
- org.apache.wicket.spring.injection.annot.AnnotProxyFieldValueFactory
-
- All Implemented Interfaces:
IFieldValueFactory
public class AnnotProxyFieldValueFactory extends Object implements IFieldValueFactory
IFieldValueFactory
that usesLazyInitProxyFactory
to create proxies for Spring dependencies based on theSpringBean
annotation applied to a field. This class is usually used by theSpringComponentInjector
to inject objects with lazy init proxies. However, this class can be used on its own to create proxies for any field decorated with aSpringBean
annotation.Example:
IFieldValueFactory factory = new AnnotProxyFieldValueFactory(contextLocator); field = obj.getClass().getDeclaredField("dependency"); IDependency dependency = (IDependency)factory.getFieldValue(field, obj);
In the example above thedependency
object returned is a lazy init proxy that will look up the actual IDependency bean from spring context upon first access to one of the methods.This class will also cache any produced proxies so that the same proxy is always returned for the same spring dependency. This helps cut down on session size beacause proxies for the same dependency will not be serialized twice.
- Author:
- Igor Vaynberg (ivaynberg), Istvan Devai, Tobias Soloschenko
- See Also:
LazyInitProxyFactory
,SpringBean
,SpringBeanLocator
,Inject
-
-
Constructor Summary
Constructors Constructor Description AnnotProxyFieldValueFactory(ISpringContextLocator contextLocator)
AnnotProxyFieldValueFactory(ISpringContextLocator contextLocator, boolean wrapInProxies)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.springframework.beans.factory.config.BeanDefinition
getBeanDefinition(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, String name)
Object
getFieldValue(Field field, Object fieldOwner)
Returns the value the field will be set toboolean
supportsField(Field field)
Returns true if the factory can generate a value for the field, false otherwise.
-
-
-
Constructor Detail
-
AnnotProxyFieldValueFactory
public AnnotProxyFieldValueFactory(ISpringContextLocator contextLocator)
- Parameters:
contextLocator
- spring context locator
-
AnnotProxyFieldValueFactory
public AnnotProxyFieldValueFactory(ISpringContextLocator contextLocator, boolean wrapInProxies)
- Parameters:
contextLocator
- spring context locatorwrapInProxies
- whether or not wicket should wrap dependencies with specialized proxies that can be safely serialized. in most cases this should be set to true.
-
-
Method Detail
-
getFieldValue
public Object getFieldValue(Field field, Object fieldOwner)
Description copied from interface:IFieldValueFactory
Returns the value the field will be set to- Specified by:
getFieldValue
in interfaceIFieldValueFactory
- Parameters:
field
- field being injectedfieldOwner
- instance of object being injected- Returns:
- new field value
-
getBeanDefinition
public org.springframework.beans.factory.config.BeanDefinition getBeanDefinition(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, String name)
-
supportsField
public boolean supportsField(Field field)
Description copied from interface:IFieldValueFactory
Returns true if the factory can generate a value for the field, false otherwise. If this method returns false, getFieldValue() will not be called on this factory- Specified by:
supportsField
in interfaceIFieldValueFactory
- Parameters:
field
- field- Returns:
- true if the factory can generate a value for the field, false otherwise
-
-