我担心在其他服务中使用服务。有些工作,但其他人没有。问题是我无法弄清楚错误。
当你添加一个生成错误的服务总是出现同样的问题时,我撤回对服务有问题的引用,系统恢复正常。
我想知道是否会影响任何创建不稳定性的循环引用。
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引用时会发生错误。
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
答案 0 :(得分:1)
每当我们使用prototype
作用域服务时,我们都会遇到类似的问题(不确定这是否适用于您)。
作为一种解决方法,您可以通过不注入tabService但按需获取它来解决它:
def getTabService() {
grailsApplication.mainContext.getBean(TabService)
}
显然不太理想。