scope
默认service是单例的,可以通过scope改变:
(1)prototype:每次注入到其它类中时,都新建一个service实例
(2)request:会为每次请求创建一个service
(3)flash:会为当前和下一次请求创建一个service
(4)flow:In web flows the service will exist for the scope of the flow
(5)conversation:In web flows the service will exist for the scope of the conversation.
(6)session:为每个用户session创建一个service实例
(7)singleton:默认。
class BookService {
static scope = "session"
…
}
transactional
默认service是没有自动事物管理的。通过设置transactional=true,可以使用其中的方法都支持spring的事务管理,默认是PROPAGATION_REQUIRED。
class BookService {
static transactional = true
…
}
最后欢迎大家访问我的个人网站:1024s