【发布时间】:2014-04-18 16:33:52
【问题描述】:
我曾经在我的 bean 上使用 Spring 事务注解。 然而,来自 Akka 的演员不情愿。 这是我在 Scala 中的代码 sn-p:
@Service
@Transactional
@Scope("prototype")
class MyActor extends Actor with ActorLogging {
def receive = {
//...... throwing a NotInTransaction (no matter what the calling lib is)
}
}
但是,@Transactional 适用于我所有其他非演员 bean。
我将 Java 添加为标记,因为我猜这可能与 Akka for Java 有类似的问题。
我错过了什么吗?
我指出我事先遵循了这项技术(我在 Scala 中进行了改编)以使我的演员创作意识到 Spring: http://www.typesafe.com/activator/template/akka-java-spring
更新示例------------
@Service("eventsListenerActor")
@Scope("prototype")
class EventsListenerActor @Autowired()(val eventRepository: EventRepository) extends Actor {
def receive = {
case RetrieveNewEvents =>
val newEvents = eventRepository.findNewEvents(EventBatchSizeProperty)
}
}
@Repository
class MyEventRepository extends EventRepository {
@Transactional //transactional annotation here
def findNewEvents(batchSize: Int): List[Event] = {
//................ code warning that transaction context is not present here !
}
}
对参与者外部的findNewEvents 的任何调用都会很好地构建事务上下文。
正如我在下面的 cmets 中所问的,它可能与 actor 及其线程方式有关吗?
【问题讨论】: