Grails服务使用来自其他服务的方法 [英] Grails service using a method from another service

查看:133
本文介绍了Grails服务使用来自其他服务的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个Grails应用程序,并尝试在不同的服务中尝试安装服务时遇到了问题。这两个服务都使用另一个定义的方法,例如。

  class fooService {
def barService
barService.doIt()

get getIt(){
...
}
}

class barService {
()$ {

}
}
当我运行该应用程序并转到使用方法的位置时,它会引发此错误;
$ b

$ b> $ b

 创建名为'fooService'的bean时出错:
org.springframework.beans.factory.FactoryBeanNotInitializedException:FactoryBean是
尚未完全初始化

这是在grails中无法完成的事情吗?或者任何人都可以提供任何建议?



谢谢

在过去有类似的问题,但只有当这两种服务都是交易性的。如果可能至少有一个是非事务性的,那么它应该按原样工作。如果这是不可能的,那么回退就是做一种后期绑定。

  class FooService {
def grailsApplication
private getBarService(){
grailsApplication.mainContext.barService
}

public methodThatUsesBarService(){
barService.doSomething()
}

$ / code>

这会查找 barService 在使用它的地方,而不是在创建 FooService 的地方。


I'm building a grails app and have come across an issue when trying to instatiate a service, in a different service. Both of the services use a method defined in the other eg.

class fooService{
    def barService
    barService.doIt()

    def getIt(){
    ...
    }
}

class barService{
    def fooService
    fooService.getIt()

    def doIt(){
    ...
    }
}

When I run the app and go to where the methods are used, it brings up this error;

Error creating bean with name 'fooService': 
org.springframework.beans.factory.FactoryBeanNotInitializedException: FactoryBean is 
not fully initialized yet

Is this something that cannot be done in grails? Or could anyone offer any advice?

Thanks

解决方案

I've had similar issues in the past, but only when both services are transactional. If it's possible to make at least one of them non-transactional then it should work as-is. If that's not possible then the fallback is to do a kind of "late binding"

class FooService {
  def grailsApplication
  private getBarService() {
    grailsApplication.mainContext.barService
  }

  public methodThatUsesBarService() {
    barService.doSomething()
  }
}

This will look up barService in the app context at the point where it is used, rather than at the point where the FooService is created.

这篇关于Grails服务使用来自其他服务的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆