【问题标题】:Grails 2.2.1 is not reading plugin Config fileGrails 2.2.1 没有读取插件配置文件
【发布时间】:2013-03-28 23:47:00
【问题描述】:

我有一个使用 Grails 2.1.1 构建的应用程序和一个插件,我升级到了 2.2.1,但遇到了一个奇怪的问题。我的应用程序开始崩溃,因为我的应用程序 Config.groovy 中定义的配置值突然解析为 groovy.Util.ConfigObject 而不是它们的实际值。这是问题的第 1 部分,第 2 部分是在我的应用程序中,我在我的应用程序的 Config.groovy 中定义了@

grails.config.defaults.locations = [
    "classpath:DemoPluginConfig.groovy",
]

DemoPluginConfig.groovy 包含此属性

oo.memcached.timeout=400000

DemoPluginConfig.groovy 文件位于我的 Demo 插件的 src/java 文件夹中。 我有一个 memcache 服务,一旦服务准备好,我将尝试设置该超时属性:

def void afterPropertiesSet() {

        ConnectionFactoryBuilder cfb = new ConnectionFactoryBuilder()
        def config = grailsApplication.config;
        def operationTimeOut = config.oo.memcached.timeout
        cfb.setOpTimeout(timeOut)

    }

grails run-app 在这一点上出现错误:

Caused by MissingMethodException: No signature of method: net.spy.memcached.ConnectionFactoryBuilder.setOpTimeout() is applicable for argument types: (groovy.util.ConfigObject) values: [[:]]
Possible solutions: setOpTimeout(long)
->>   55 | unwrap                          in org.codehaus.groovy.runtime.ScriptBytecodeAdapter
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|     46 | call                            in org.codehaus.groovy.runtime.callsite.PojoMetaClassSite
|     45 | defaultCall . . . . . . . . . . in org.codehaus.groovy.runtime.callsite.CallSiteArray
|    108 | call                            in org.codehaus.groovy.runtime.callsite.AbstractCallSite
|    116 | call . . . . . . . . . . . . .  in     ''
|     20 | afterPropertiesSet              in com.millennialmedia.ui.core.MemcachedService
|   1514 | invokeInitMethods . . . . . . . in org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
|   1452 | initializeBean                  in     ''
|    519 | doCreateBean . . . . . . . . .  in     ''
|    122 | doCreateBean                    in org.codehaus.groovy.grails.commons.spring.ReloadAwareAutowireCapableBeanFactory
|    456 | createBean . . . . . . . . . .  in org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
|    271 | resolveInnerBean                in org.springframework.beans.factory.support.BeanDefinitionValueResolver
|    126 | resolveValueIfNecessary . . . . in     ''
|   1360 | applyPropertyValues             in org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
|   1118 | populateBean . . . . . . . . .  in     ''

如果我尝试再运行 grails run-app 几次,它会成功启动,但应用程序会在加载另一个页面时崩溃,另一个 groovy.Util.ConfigObject is not serializable 错误。在应用程序崩溃之前逐步调试表明,当我们到达setOptTimeOut 行时,grailsApplication.config 仅包含我应用程序的 Config.groovy 中的配置选项,就好像插件 DemoPLuginConfig.groovy 中的值被忽略了一样.

恢复到 2.1.1 使一切恢复正常。在这一点上,我不知道在哪里看。

【问题讨论】:

  • 我遇到了类似的问题,但反过来——我的插件将其 conf 文件复制到客户端的 conf 目录中,并且在运行 grails upgrade (2.2.1) 后,插件的 conf 优先于客户端的版本被读取。所以我看到的是 grails 升级正在填充类路径解析和/或排序。

标签: grails upgrade config


【解决方案1】:

您不应该在下面使用operationTimeOut 而不是timeOut

cfb.setOpTimeout(timeOut)

【讨论】:

  • 它实际上在代码中设置为 operationTimeout 但这不是错误发生的原因
【解决方案2】:

尝试将您的 Groovy 配置放入 grails-app/conf 而不是 src/java。然后,看看您是否可以始终如一地重现您的错误。

如果全部失败,grails clean 可能会占上风。

希望对你有帮助

【讨论】:

  • 我会尝试并告诉你
猜你喜欢
  • 2017-11-03
  • 1970-01-01
  • 2010-12-24
  • 1970-01-01
  • 2010-10-25
  • 2012-01-27
  • 1970-01-01
  • 1970-01-01
  • 2012-10-19
相关资源
最近更新 更多