我同意。
你怎麼知道它不起作用?我們正在使用Grails 2.3.9。
我有這個在我的resources.groovy:
httpBuilderPool(HTTPBuilder) { bean ->
bean.scope = 'prototype' // A new service is created every time it is injected into another class
client = ref('httpClientPool')
}
...
,這在斯波克集成測試:
import grails.test.spock.IntegrationSpec
import org.apache.http.impl.client.CloseableHttpClient
import org.apache.log4j.Logger
class JukinHttpBuilderSpec extends IntegrationSpec {
private final Logger log = Logger.getLogger(getClass())
def httpBuilderPool
def grailsApplication
void "test jukinHttpBuilder instantiates"() {
expect:
httpBuilderPool
httpBuilderPool.client instanceof CloseableHttpClient
}
void "test httpBuilderPool is prototype instaance"() {
when: 'we call getBean on the application context'
def someInstanceIds = (1..5).collect { grailsApplication.mainContext.getBean('httpBuilderPool').toString() }.toSet()
log.info someInstanceIds.toString()
then: 'we should get a new instance every access'
someInstanceIds.size() == 5
}
void "test injected httpBuilderPool is prototype instance"() {
when: 'we access the injeted httpBuilderPool'
def someInstanceIds = (1..5).collect { httpBuilderPool.toString() }.toSet()
log.info someInstanceIds.toString()
then: 'it uses the same instance every time'
someInstanceIds.size() == 1
}
}
這說明我的工作在2.3.9。
「我在文檔中找不到任何東西」 - 在第18.3節中,有一個示例將sessionFactory bean配置爲請求作用域。該示例沒有具體說明如何配置原型範圍的bean,但所有範圍的語法都是相同的。只需將「請求」替換爲「原型」即可。 –
@JeffScottBrown對不起,我錯過了。我在該文檔中掠過並搜索了原型 – mzzzzb