Wicket @SpringBean doesn't create serializable proxy

蓝咒 提交于 2019-12-22 10:45:41

问题


@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?


回答1:


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.




回答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.




回答3:


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



来源:https://stackoverflow.com/questions/4544802/wicket-springbean-doesnt-create-serializable-proxy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!