简体   繁体   English

Grails 2.3奇怪的插件渴望加载行为

[英]Grails 2.3 strange plug-in eager loading behavior

I've just added a custom local plug-in (via 'grails.plugin.location...' build config declaration) to a grails 2.3 project. 我刚刚将一个自定义的本地插件(通过'grails.plugin.location ...'构建配置声明)添加到了grails 2.3项目中。 As soon as I add the plug-in and try to run my application I see a strange behavior whereby all of the beans in my main application suddenly try to eagerload across the board. 一旦添加了插件并尝试运行我的应用程序,我就会看到一个奇怪的行为,即主应用程序中的所有bean突然都试图全盘加载。 Ie if I have: 即如果我有:

class FooService {
  BarService barService
}

class BarService {
  FooService fooService
}

Then the application cannot start. 然后应用程序无法启动。 There is no code being executed in FooService or BarService at init time that should cause the Spring context to need to unwrap the either fooService or barService instance but that behavior seems to be happening anyway. 初始化时没有在FooService或BarService中执行的代码会导致Spring上下文需要解开fooService或barService实例,但是这种行为似乎仍在发生。 In the end the application init fails with an exception like: 最后,应用程序初始化失败,并出现以下异常:

Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'fooService': org.springframework.beans.factory.FactoryBeanNotInitializedException: FactoryBean is not fully initialized yet 引起原因:org.springframework.beans.factory.BeanCurrentlyInCreationException:创建名称为'fooService'的bean时出错:org.springframework.beans.factory.FactoryBeanNotInitializedException:FactoryBean尚未完全初始化

As the fooService requires the barService, which requires the fooService which is still being created. 由于fooService需要barService,而barService需要仍在创建的fooService。

As soon as I remove the dependency on the custom plug-in then the problem stops. 一旦删除对自定义插件的依赖性,问题就会停止。 Obviously something either in the plugin or about the plugin (meta data or something) is causing this behavior but I can't figure out what exactly. 显然,插件中或插件中的某些内容(元数据或其他内容)导致了此行为,但我无法弄清楚到底是什么。

Rather than a solution I think what I am looking for here is some trouble-shooting techniques or information leading me to understand why this eagerloading behavior is occurring. 我认为不是在寻找解决方案,而是我在寻找的是一些故障排除技术或信息,这些信息或信息使我理解为什么这种急切的行为正在发生。 I just don't know what the right hooks/configs are that will let me get in the head of the Spring context initialization mechanism. 我只是不知道什么是正确的钩子/配置,这些使我进入Spring上下文初始化机制的顶端。

I found the answer to my question buried deep in the comments of this other SO question: Grails service using a method from another service 我在另一个SO问题的注释中发现了问题的答案: Grails服务使用另一个服务中的方法

Basically my plugin introduced the hibernate plug-in into my project and therefore also introduced transactional-by-default services. 基本上,我的插件将hibernate插件引入了我的项目,因此也引入了默认事务处理服务。 This transactional bootstrapping was causing the eager load of all dependencies and thus my circular dependency problem. 这种事务性引导正在引起所有依赖性的迫切负载,从而导致了我的循环依赖性问题。

The fix was to, at least for now, mark the circularly dependent services as non-transactional. 解决方法是至少至少现在将循环依赖服务标记为非事务性。 Of course in the future if I need those services to be transactional it seems I will need to re-architect my service setup. 当然,将来如果我需要这些服务来进行事务处理,似乎我将需要重新设计服务设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM