3
@SpringBean
PDLocalizerLogic loc;

When using above I receive java.io.NotSerializableException. 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?

vinga
  • 1,912
  • 20
  • 33
  • +1 simply because this is the first place I've heard wrapInProxies mentioned, and I managed to chase it down (didn't write the Application class myself) and it solved all my problems :) – Svend Hansen Oct 17 '12 at 10:48

3 Answers3

3

Do you know how the bean is being injected?

  1. Through component initialization (i.e. a Component and being filled in by the SpringComponentInjector)
  2. Some other object using InjectorHolder.getInjector().inject(this)?
  3. 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.

Matt
  • 1,119
  • 7
  • 13
  • Hmm..I'm using InjectorHolder.getInjector().inject(this) because the class isn't wicket component, so the bean should be serializable. – vinga Jan 20 '11 at 12:13
  • Then are you sure it is loc that is in violation of being not serializable? Is there something else here that is causing this? – Matt Jan 20 '11 at 18:23
  • It was my falt, I hadn't noticed that I had different config for Mock application (wrapInProxies set to false). I've changed it and everything works as expected. Sorry for bothering you! – vinga Jan 21 '11 at 15:41
2

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.

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
  • In this case, it is actually Wicket who should create the proxies (it uses CGLib under the covers for concrete classes, and regular Java proxies for interfaces). – Eelco Dec 28 '10 at 18:40
1

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

Community
  • 1
  • 1
Eelco
  • 1,718
  • 22
  • 16