【问题标题】:Is the Grails RestBuilder thread-safe?Grails RestBuilder 是线程安全的吗?
【发布时间】:2016-10-26 15:25:14
【问题描述】:

'grails.plugins.rest.client.RestBuilder' 线程安全吗?

是否可以通过 resources.groovy 将其注入到 grails 服务中?

谢谢

标记

【问题讨论】:

  • 第二个问题的答案是“是”。即使对于不是线程安全的东西也是如此。如果您将非线程安全 bean 注入到其他 bean 中,则应将这些其他 bean 配置为请求范围或原型范围,具体取决于它们的使用方式。您只需要确保没有 2 个线程同时与任何非线程安全 bean 交互。
  • resources.groovy中如何指定bean的代理范围? scopedProxy 不起作用 testBean(TestBean){ it.scope = 'request' it.scopedProxy = ScopedProxyMode.TARGET_CLASS }
  • it.scope = 'request' 应该可以工作。根据您检索 bean 的方式,它可能看起来不像。

标签: grails


【解决方案1】:
restBuilderContainer(RestBuilder) {
    it.scope = 'request'
}

restBuilder(ScopedProxyFactoryBean) {
    targetBeanName = 'restBuilderContainer'
    proxyTargetClass = true
}

ScopedProxyFactoryBean 成功了。

【讨论】:

    猜你喜欢
    • 2021-10-12
    • 2015-04-18
    • 2011-10-07
    • 2012-03-02
    • 2011-10-28
    • 2023-03-14
    • 2016-08-24
    • 2011-08-16
    • 2011-09-28
    相关资源
    最近更新 更多