Grails服务中的服务声明错误 [英] Error in Declaration of service within Grails service
问题描述
我对在其他服务中使用服务感到担忧.有些工作,但是其他却没有.问题是我不知道怎么了.
I have concerns about the use of Services within other Services. Some work, but others don't. The problem is that I can't figure out what's wrong.
当您添加生成错误的服务时,总是会出现相同的问题,因此我撤消了对有问题的服务的引用,系统恢复了正常.
When you add a service that generates the error always occurs the same problem, then I withdraw the reference to service problematic and the system returns to normal.
我想知道这是否会影响任何循环引用,从而造成不稳定.
I wonder if the same is effecting any circular reference creating instability.
class UserService {
def terceirizadoService
def unidadeService
def grailsApplication
def springSecurityService
def tabService //If I remove this line the system works
...
}
class TabService {
def contratoService, grailsApplication ...
}
当对具有对tabService服务的引用的域进行Bootstrap引用时,会发生错误.
The error happens when the Bootstrap reference is made to a domain that has a reference to the tabService service.
class Car implements Serializable {
transient tabService
...
}
并生成此日志:
Caused by BeanCreationException: Error creating bean with name ‘tabService’: Cannot create inner bean '(inner bean)' while setting bean property 'target'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#2': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contratoService': Cannot create inner bean '(inner bean)' while setting bean property 'target'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#3': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘userService’: Cannot create inner bean '(inner bean)' while setting bean property 'target'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#5': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name ‘tabService’: org.springframework.beans.factory.FactoryBeanNotInitializedException: FactoryBean is not fully initialized yet
->> 105 | methodMissing in org.grails.datastore.gorm.GormStaticApi
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 558 | doCall in BootStrap$_closure1
| 308 | evaluateEnvironmentSpecificBlock in grails.util.Environment
| 301 | executeForEnvironment in ''
| 277 | executeForCurrentEnvironment . . in ''
| 262 | run in java.util.concurrent.FutureTask
| 1145 | runWorker . . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | run . . . . . . . . . . . . . . in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name '(inner bean)#2': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contratoService': Cannot create inner bean '(inner bean)' while setting bean property 'target'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#3': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘userService’: Cannot create inner bean '(inner bean)' while setting bean property 'target'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#5': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name ‘tabService’: org.springframework.beans.factory.FactoryBeanNotInitializedException: FactoryBean is not fully initialized yet
->> 105 | methodMissing in org.grails.datastore.gorm.GormStaticApi
我正在使用Grails 2.3.7
I'm using Grails 2.3.7
推荐答案
每当我们使用prototype
作用域服务时(我们不确定是否适用于您),我们也遇到过类似的问题.
We've seen issues like this whenever we use prototype
scoped services as well (not sure if that applies to you).
作为解决方法,您可以通过不注入tabService而是按需获取它来解决该问题:
As a work around you could solve it by not injecting the tabService but getting it on demand:
def getTabService() {
grailsApplication.mainContext.getBean(TabService)
}
显然不理想.
这篇关于Grails服务中的服务声明错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!