Wicket @SpringBean 不创建可序列化代理
@SpringBean
PDLocalizerLogic loc;
当使用上面时,我收到 java.io.NotSerializedException。这是因为 loc 不可序列化,但这不应该成为问题,因为 spring bean 是可序列化代理。 我使用 wicket-spring 库,并作为注入器 SpringComponentInjector,其中 wrapInProxies 默认设置为 true,所以我认为应该创建代理,但事实并非如此。
在页面上 https://cwiki.apache.org/WICKET/spring.html# Spring-AnnotationbasedApproach 写法:
使用基于注释的方法,您 不应该担心 的序列化/反序列化 注入的依赖项是这样的 自动处理, 依赖关系表示为 可序列化代理
我做错了什么?
@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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你知道豆子是如何注入的吗?
情况 1 和 2 将使用 wicket-spring 集成,并使用可序列化的 wicket 代理包装该 bean。
情况 3 只会为您提供不包装的弹簧传递给您的任何内容。
Do you know how the bean is being injected?
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.
首先,确保您的 bean 确实被代理了。默认情况下spring不创建代理。
其次,检查您的代理策略 - 是否为
proxy-target-class="true"
。如果它是 false,(据我所知)对对象的引用将存储在 JDK 代理的调用处理程序中,并尝试进行序列化。因此,如果需要的话,您还需要使您的类可序列化。
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 isfalse
, (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.您能否仔细检查实例化侦听器是否已添加到您的应用程序类中:
addComponentInstantiationListener(new SpringComponentInjector(this));
此外,这仅适用于 Wicket 组件中的字段,不适用于任意类。
另请参阅 wicket @SpringBean 无法创建 bean
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