问题
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 ...
}
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
...
}
and generates this log:
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
I'm using Grails 2.3.7
回答1:
We've seen issues like this whenever we use prototype
scoped services as well (not sure if that applies to you).
As a work around you could solve it by not injecting the tabService but getting it on demand:
def getTabService() {
grailsApplication.mainContext.getBean(TabService)
}
Not ideal, obviously.
来源:https://stackoverflow.com/questions/23685583/error-in-declaration-of-service-within-grails-service