Spring-Batch @BeforeStep不适用于@StepScope

Spring-Batch @BeforeStep不适用于@StepScope,第1张

Spring-Batch @BeforeStep不适用于@StepScope

当你按如下方式配置bean时:

@Bean@StepScopepublic MyInterface myBean() {    return new MyInterfaceImpl();}

你正在告诉Spring使用代理模式

ScopedProxyMode.TARGET_CLASS
。但是,通过返回
MyInterface
而不是返回,
MyInterfaceImpl
代理仅具有对上方法的可见性
MyInterface
。这将阻止
Spring Batch
能够在
MyInterfaceImpl
已使用侦听器注释(例如)进行注释的方法上找到方法@BeforeStep。正确
MyInterfaceImpl
的配置方法是返回你的配置方法,如下所示:

@Bean@StepScopepublic MyInterfaceImpl myBean() {    return new MyInterfaceImpl();}

我们在启动时添加了一条警告日志消息,该消息指出,当我们寻找带注释的侦听器方法时,如果该对象被代理并且目标是接口,则将无法在实现类上找到带有注释的方法他们。



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5110105.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-17
下一篇 2022-11-17

发表评论

登录后才能评论

评论列表(0条)

保存