将grails从2.1.1升级到2.4.3

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将grails从2.1.1升级到2.4.3相关的知识,希望对你有一定的参考价值。

我正在将grails应用程序从2.1.1升级到2.4.3,并且在升级过程中解决错误是一个永无止境的故事。

现在我陷入了困境。

任何想法如何解决这个问题?

谢谢!

C: workspace grails_apps monitoring> grails run-app

| Running Grails application
| Error 2014-09-20 17:36:55,136 [localhost-startStop-1] ERROR context.ContextLoader  - Context initialization failed
Message: Error creating bean with name 'grailsApplication' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'grailsResourceLoader' while setting bean property 'grailsResourceLoader'; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.codehaus.groovy.grails.commons.GrailsResourceLoaderFactoryBean] for bean with name 'grailsResourceLoader' defined in ServletContext resource [/WEB-INF/appli
cationContext.xml]; nested exception is java.lang.ClassNotFoundException: org.codehaus.groovy.grails.commons.GrailsResourceLoaderFactoryBean
    Line | Method
->>  334 | innerRun  in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    166 | run       in java.util.concurrent.FutureTask
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run . . . in java.lang.Thread

Caused by CannotLoadBeanClassException: Cannot find class [org.codehaus.groovy.grails.commons.GrailsResourceLoaderFactoryBean] for bean with name 'grailsResourceLoader' defined in ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: org.codehaus.groovy.grails.commons.GrailsResourceLoaderFactoryBean
->>  334 | innerRun  in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    166 | run       in java.util.concurrent.FutureTask
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run . . . in java.lang.Thread

Caused by ClassNotFoundException: org.codehaus.groovy.grails.commons.GrailsResourceLoaderFactoryBean
->>   59 | findClass in org.grails.plugins.tomcat.ParentDelegatingClassLoader
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    423 | loadClass in java.lang.ClassLoader
|    356 | loadClass in     ''
|    334 | innerRun  in java.util.concurrent.FutureTask$Sync
|    166 | run . . . in java.util.concurrent.FutureTask
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run       in java.lang.Thread
| Error 2014-09-20 17:36:55,270 [localhost-startStop-1] ERROR context.GrailsContextLoaderListener  - Error initializing the application: Error creating bean with name 'grailsApplication' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'grailsResourceLoader' while setting bean property 'grailsResourceLoader'; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.codehaus.groovy.grails.commo
ns.GrailsResourceLoaderFactoryBean] for bean with name 'grailsResourceLoader' defined in ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: org.codehaus.groovy.grails.commons.GrailsResourceLoaderFactoryBean
Message: Error creating bean with name 'grailsApplication' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'grailsResourceLoader' while setting bean property 'grailsResourceLoader'; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.codehaus.groovy.grails.commons.GrailsResourceLoaderFactoryBean] for bean with name 'grailsResourceLoader' defined in ServletContext resource [/WEB-INF/appli
cationContext.xml]; nested exception is java.lang.ClassNotFoundException: org.codehaus.groovy.grails.commons.GrailsResourceLoaderFactoryBean
    Line | Method
->>  334 | innerRun  in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    166 | run       in java.util.concurrent.FutureTask
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run . . . in java.lang.Thread

Caused by CannotLoadBeanClassException: Cannot find class [org.codehaus.groovy.grails.commons.GrailsResourceLoaderFactoryBean] for bean with name 'grailsResourceLoader' defined in ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: org.codehaus.groovy.grails.commons.GrailsResourceLoaderFactoryBean
->>  334 | innerRun  in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    166 | run       in java.util.concurrent.FutureTask
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run . . . in java.lang.Thread

Caused by ClassNotFoundException: org.codehaus.groovy.grails.commons.GrailsResourceLoaderFactoryBean
->>   59 | findClass in org.grails.plugins.tomcat.ParentDelegatingClassLoader
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    423 | loadClass in java.lang.ClassLoader
|    356 | loadClass in     ''
|    334 | innerRun  in java.util.concurrent.FutureTask$Sync
|    166 | run . . . in java.util.concurrent.FutureTask
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run       in java.lang.Thread

BuildConfig.groovy

grails.servlet.version = "2.5" // Change depending on target container compliance (2.5 or 3.0)
grails.server.port.http = 8090
grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"
grails.project.target.level = 1.6
grails.project.source.level = 1.6
grails.project.dependency.resolver = "maven" 
//grails.project.war.file = "target/${appName}-${appVersion}.war"

// uncomment (and adjust settings) to fork the JVM to isolate classpaths
//grails.project.fork = [
//   run: [maxMemory:1024, minMemory:64, debug:false, maxPerm:256]
//]

grails.project.dependency.resolution = {
    // inherit Grails' default dependencies
    inherits("global") {
        // specify dependency exclusions here; for example, uncomment this to disable ehcache:
        // excludes 'ehcache'
    }
    log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
    checksums true // Whether to verify checksums on resolve
    legacyResolve false // whether to do a secondary resolve on plugin installation, not advised and here for backwards compatibility

    repositories {
        inherits true // Whether to inherit repository definitions from plugins

        grailsPlugins()
        grailsHome()
        grailsCentral()

        mavenLocal()
        mavenCentral()

        // uncomment these (or add new ones) to enable remote dependency resolution from public Maven repositories
        //mavenRepo "http://snapshots.repository.codehaus.org"
        //mavenRepo "http://repository.codehaus.org"
        //mavenRepo "http://download.java.net/maven/2/"
        //mavenRepo "http://repository.jboss.com/maven2/"
    }

    dependencies {
        // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes e.g.

        // runtime 'mysql:mysql-connector-java:5.1.20'


    }

    plugins {
        runtime ":hibernate4:4.3.5.5"
        runtime ":jquery:1.11.1"

        build ":tomcat:7.0.54"

        runtime ":database-migration:1.4.0"

    }

}

我尝试创建一个新的应用程序并将文件复制到新项目,而不是升级现有的grails应用程序。这种方法会导致不同的错误。

grails run-app

| Running Grails application
Error occurred during initialization of VM
agent library failed to init: instrument
Error opening zip file or JAR manifest missing : C:Program%20Files%20(x86)Grailsgrails-2.4.3liborg.springframeworkspringloadedjarsspringloaded-1.2.0.RELEASE.jar
| Error Forked Grails VM exited with error

使用的java版本:1.7.0_21

GRAILS_HOME = C: PROGRA〜2周的grails 的grails-2.4.3

GROOVY_HOME = C: PROGRA〜2 Groovy的 Groovy的2.3.6

Grails版本:2.4.3

现在做什么?

谢谢!

----------------------------------------------------

根据以下建议删除对bean'grailsResourceLoader的引用,我相应地更改了applicationContext.xml。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

    <bean id="grailsApplication" class="org.codehaus.groovy.grails.commons.GrailsApplicationFactoryBean">
        <description>Grails application factory bean</description>
        <property name="grailsDescriptor" value="/WEB-INF/grails.xml" />
    </bean>

    <bean id="pluginManager" class="org.codehaus.groovy.grails.plugins.GrailsPluginManagerFactoryBean">
        <description>A bean that manages Grails plugins</description>
        <property name="grailsDescriptor" value="/WEB-INF/grails.xml" />
        <property name="application" ref="grailsApplication" />
    </bean>

    <bean id="grailsConfigurator" class="org.codehaus.groovy.grails.commons.spring.GrailsRuntimeConfigurator">
        <constructor-arg>
            <ref bean="grailsApplication" />
        </constructor-arg>
        <property name="pluginManager" ref="pluginManager" />
    </bean>


    <bean id="characterEncodingFilter" class="org.springframework.web.filter.CharacterEncodingFilter">
        <property name="encoding">
            <value>utf-8</value>
        </property>
    </bean>
</beans>

不幸的是,问题仍然存在。

| Running Grails application
Error opening zip file or JAR manifest missing : C:Program%20Files%20(x86)Grailsgrails-2.4.3liborg.springframeworkspringloadedjarsspringloaded-1.2.0.RELEASE.jar
Error occurred during initialization of VM
agent library failed to init: instrument
| Error Forked Grails VM exited with error

感谢您的任何进一步帮助!!

-----------------------------------------

Grails 2.4.3需要Java 1.8.0吗?

  • 不,不是,即使对于java 8,问题也是一样的
答案

我能够通过创建一个新的2.4 grails项目并将applicationContext.xml文件从它复制到我现有的项目来解决这个问题。

另一答案

您的较新版本的Grails在applicationContent.xml中不需要这两行:

<property name="grailsResourceLoader" ref="grailsResourceLoader" />

<bean id="grailsResourceLoader" class="org.codehaus.groovy.grails.commons.GrailsResourceLoaderFactoryBean" />

删除它们并重新启动项目。它应该工作得很好。

另一答案

对于任何感兴趣的人,通过更改我的Grails SDK的位置来解决这个问题:

C:Program Files (x86)Grailsgrails-2.4.3

C:Grailsgrails-2.4.3

例如。删除GRAILS_HOME路径中的空格,如发现here的帖子中所述。

注意,通过设置GROOVY_HOME = C: PROGRA~2 Grails grails-2.4.3删除空格不起作用

另一答案

我得到了相同的错误,但将grails升级到2.5.5版本,希望它对你有帮助。

在applicationContext.xml中:

<bean id="grailsApplication" class="org.codehaus.groovy.grails.commons.GrailsApplicationFactoryBean">
    <description>Grails application factory bean</description>
    <property name="grailsDescriptor" value="/WEB-INF/grails.xml" />
    <property name="grailsResourceLoader" ref="grailsResourceLoader" />
</bean>

删除grailsResourceLoader,将其保留为:

<bean id="grailsApplication" class="org.codehaus.groovy.grails.commons.GrailsApplicationFactoryBean">
    <description>Grails application factory bean</description>
    <property name="grailsDescriptor" value="/WEB-INF/grails.xml" />
</bean>

我确实使用了这个链接:https://grails.github.io/grails2-doc/2.5.5/guide/upgradingFrom23.html

以上是关于将grails从2.1.1升级到2.4.3的主要内容,如果未能解决你的问题,请参考以下文章

将 Grails 应用程序从 3.1.10 升级到 3.2.5 时出错

Grails,从 Acegi 升级到 Spring 安全插件

Grails从1.3升级到2.4

Grails 从 2.2.1 升级到 2.3.4 @Secured Annotation

从 2.1 升级到 2.2.4 后 Grails 自动编译中断

Grails 从 2.4.5 升级到 3.3.2:关系“xxx”不存在