Wicket @SpringBean 不创建可序列化代理

发布于 2024-10-09 17:33:23 字数 580 浏览 3 评论 0原文

@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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦纸 2024-10-16 17:33:23

你知道豆子是如何注入的吗?

  1. 通过组件初始化(即一个组件并由 SpringComponentInjector 填充)
  2. 使用 InjectorHolder.getInjector().inject(this) 的其他对象?
  3. 由 spring 直接注入(即,这是一个 spring bean,其中属性由 Spring 配置设置)

情况 1 和 2 将使用 wicket-spring 集成,并使用可序列化的 wicket 代理包装该 bean。
情况 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.

小镇女孩 2024-10-16 17:33:23

首先,确保您的 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 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.

鸢与 2024-10-16 17:33:23

您能否仔细检查实例化侦听器是否已添加到您的应用程序类中:

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文