0

我担心在其他服务中使用服务。有些工作,但其他人没有。问题是我无法弄清楚出了什么问题。

当你添加一个产生错误的服务时总是出现同样的问题,那么我撤回对服务有问题的引用,系统恢复正常。

我想知道这是否会影响任何造成不稳定的循环引用。

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 ...
}

当 Bootstrap 引用指向具有对 tabService 服务的引用的域时,会发生错误。

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

4

1 回答 1

1

每当我们使用prototype范围服务时,我们都会看到类似的问题(不确定这是否适用于您)。

作为一种解决方法,您可以通过不注入 tabService 而是按需获取它来解决它:

def getTabService() {
    grailsApplication.mainContext.getBean(TabService)
}

显然,不理想。

于 2014-05-16T16:47:08.860 回答