java - Is it a good practice to make one Spring bean inherit another one?
问题描述
In my Spring Boot web application there are two beans, one of them inherits other one and both implements an interface. Something line this:
@Component
public class A implements SomeInterface {
// ....
}
@Component
public class B extends A implements SomeInterface {
// ....
}
Is it a good idea to make one bean extending another one or it's better use a decorator? And why?
I don't mean any specific case but general one.
解决方案
No because it will fail if you inject it by interface or the super class. If you inject A now it is ambiguous.
推荐阅读
- java - 如何使用 Jpackage 为 JavaFX 应用程序制作分发格式
- php - createorupdate 功能不起作用。填充模型缺少参数
- php - Laravel View::make 不渲染
- javascript - JS 联系人自动完成事件(IOS 键盘)
- node.js - EACCES:权限被拒绝,mkdir '/root/.npm/sentry-cli'
- javascript - 如何在页面内导航以做出反应?
- java - 如何使用 Reactor 调度程序优雅地关闭?
- node.js - 类型错误:device.devices.map 不是函数
- excel - 将文件发送到其他计算机时自动添加一行
- ruby - 在 ruby 中,我们如何将两个给定的哈希合并为单个哈希,并用两个值中的较大值替换重复的键值