【发布时间】:2022-01-15 17:19:40
【问题描述】:
我的应用程序的基础设施包中有一个接口和实现。 在域层中,我想使用从基础设施接口继承的另一个接口来访问这个接口。但是Spring无法识别该接口对应的bean
基础设施包
interface PushNotificationService {
fun push(): Mono<Void>
}
@Service
class PushNotificationServiceImpl() : PushNotificationService {
override fun send(): Mono<Void> {
//Call grpc to push notification
}
}
域名包
//import PushNotificationService from the infrastructure package
interface PushNotificationService: PushNotificationService
@Service
class MessengerServiceImpl(
@Autowired val pushNotificationService: PushNotificationService //I want to use the interface defined in my domain layer
)
有什么办法可以做这样的事情吗?
【问题讨论】:
-
不,你不能,因为你的 PushNotificationService 没有实现!
-
您应该将接口移动到域模块,因为域不应该依赖于基础设施。
标签: java spring spring-boot kotlin