Wicket @SpringBean doesn't create serializable proxy
@SpringBean
PDLocalizerLogic loc;
When using above I receive java.io.NotSerializableException. 开发者_Python百科This is because loc is not serializable, but this shouldn't be problem because spring beans are a serializable proxies. I'm using wicket-spring library, and as injector SpringComponentInjector, where wrapInProxies is by default set to true, so I think that proxies should be created, but they aren't.
On the page https://cwiki.apache.org/WICKET/spring.html#Spring-AnnotationbasedApproach is written:
Using annotation-based approach, you should not worry about serialization/deserialization of the injected dependencies as this is handled automatically, the dependencies are represented by serializable proxies
What am I doing wrong?
Do you know how the bean is being injected?
- Through component initialization (i.e. a Component and being filled in by the SpringComponentInjector)
- Some other object using InjectorHolder.getInjector().inject(this)?
- Injected directly by spring (i.e. this is a spring bean where the property is being set by Spring configuration)
Cases 1 and 2 would use wicket-spring integration and would wrap the bean with a wicket proxy which is serializable. Case 3 would only provide you whatever spring passes to you without wrapping.
First, make sure your bean is really proxied. By default spring does not create proxies.
Second, check your proxying strategy - whether it is proxy-target-class="true"
or not. If it is false
, (afaik) a reference to your object is stored in the invocation handler of the JDK proxy, and is attempted to be serialized.
So you'll need to make your class Serializable
as well, if you need it to be.
Can you double check that the instantiation listener is added in your application class:
addComponentInstantiationListener(new SpringComponentInjector(this));
Also, this only works for fields in Wicket components, not arbitrary classes.
See also wicket @SpringBean can not create bean
精彩评论