public class AnnotProxyFieldValueFactory extends Object implements IFieldValueFactory
IFieldValueFactory
that uses LazyInitProxyFactory
to create proxies for Spring
dependencies based on the SpringBean
annotation applied to a field. This class is usually
used by the SpringComponentInjector
to inject objects with lazy init proxies. However,
this class can be used on its own to create proxies for any field decorated with a
SpringBean
annotation.
Example:
IFieldValueFactory factory = new AnnotProxyFieldValueFactory(contextLocator); field = obj.getClass().getDeclaredField("dependency"); IDependency dependency = (IDependency)factory.getFieldValue(field, obj);In the example above the
dependency
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.
LazyInitProxyFactory
,
SpringBean
,
SpringBeanLocator
,
Inject
Constructor and Description |
---|
AnnotProxyFieldValueFactory(ISpringContextLocator contextLocator) |
AnnotProxyFieldValueFactory(ISpringContextLocator contextLocator,
boolean wrapInProxies) |
Modifier and Type | Method and 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 to
|
boolean |
supportsField(Field field)
Returns true if the factory can generate a value for the field, false otherwise.
|
public AnnotProxyFieldValueFactory(ISpringContextLocator contextLocator)
contextLocator
- spring context locatorpublic AnnotProxyFieldValueFactory(ISpringContextLocator contextLocator, boolean wrapInProxies)
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.public Object getFieldValue(Field field, Object fieldOwner)
IFieldValueFactory
getFieldValue
in interface IFieldValueFactory
field
- field being injectedfieldOwner
- instance of object being injectedpublic org.springframework.beans.factory.config.BeanDefinition getBeanDefinition(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, String name)
public boolean supportsField(Field field)
IFieldValueFactory
supportsField
in interface IFieldValueFactory
field
- fieldCopyright © 2006–2022 Apache Software Foundation. All rights reserved.