Wicket @SpringBean does not create serializable proxies

@SpringBean PDLocalizerLogic loc; 

When using the above, I get java.io.NotSerializableException. This is because loc is not serializable, but this should not be a problem since spring beans are serializable proxies. I use the wicket-spring library and as a SpringComponentInjector injector, where wrapInProxies is set to true by default, so I think that a proxy should be created, but it is not.

At https://cwiki.apache.org/WICKET/spring.html#Spring-AnnotationbasedApproach it says:

Using the annotation approach, you do not have to worry about serializing / deserializing nested dependencies, since this is processed automatically, dependencies are represented by serializable proxies

What am I doing wrong?

+3
source share
3 answers

Do you know how bean is introduced?

  • Through component initialization (i.e., the component is populated using SpringComponentInjector)
  • Another object using InjectorHolder.getInjector (). inject (this)?
  • It is entered directly through spring (i.e. it is a spring bean where the property is set by spring configuration)

Cases 1 and 2 will use wicket-spring integration and be wrapped by a bean with a calibration proxy that is being serialized. Case 3 will give you everything spring goes without packaging.

+3
source

First make sure your bean is really proxied. By default, spring does not create proxies.

Secondly, check your proxying strategy - be it proxy-target-class="true" or not. If it is false , (afaik), the link to your object is stored in the JDK proxy call handler and tries to be serialized.

So you will need to make your Serializable class if you need it.

+2
source

Can you double check that the instantiation listener has been added to your application class:

addComponentInstantiationListener (new SpringComponentInjector (this));

In addition, this only works for fields in Wicket components, not for arbitrary classes.

See also wicket @SpringBean cannot create a bean

+1
source

Source: https://habr.com/ru/post/1345074/


All Articles