2017-07-01 90 views
0

因为已知在grails 2.3.x之后的版本中已经弃用了org.codehaus.groovy.grails.commons.ApplicationHolder类。但是有很多插件使用它。 在我的一个应用程序中,我碰巧使用了https://grails.org/plugin/excel-import?skipRedirect=true,它已被弃用,并且对于grails 2.4没有任何等价物(尽管grails 3有一个)。 我的应用程序使用这个插件,我宁愿不必折射它使用最新版本。那么有没有办法让org.codehaus.groovy.grails.commons.ApplicationHolder解析为Holders.grailsApplicationsrc/java中的Grails 2.x类未在插件中解析

我已经在SRC/java文件夹中创建一个org.codehaus.groovy.grails.commons.ApplicationHolder其中有这样的内容:

/* 
* Copyright 2004-2005 the original author or authors. 
* 
* Licensed under the Apache License, Version 2.0 (the "License"); 
* you may not use this file except in compliance with the License. 
* You may obtain a copy of the License at 
* 
*  http://www.apache.org/licenses/LICENSE-2.0 
* 
* Unless required by applicable law or agreed to in writing, software 
* distributed under the License is distributed on an "AS IS" BASIS, 
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
* See the License for the specific language governing permissions and 
* limitations under the License. 
*/ 
package org.codehaus.groovy.grails.commons; 

import grails.util.GrailsUtil; 
import grails.util.Holders; 

/** 
* Static singleton holder for the GrailsApplication instance. 
* 
* @author Marc Palmer ([email protected]) 
* 
* @deprecated Use dependency injection or implement GrailsApplicationAware instead 
*/ 
@Deprecated 
public abstract class ApplicationHolder { 

    /** 
    * @return The GrailsApplication instance 
    * @deprecated Use dependency injection instead 
    */ 
    @Deprecated 
    public static GrailsApplication getApplication() { 
     GrailsUtil.deprecated("Method ApplicationHolder.getApplication() is deprecated and will be removed in a future version of Grails."); 
     return Holders.getGrailsApplication(); 
    } 

    /** 
    * @param application The application to set 
    * @deprecated Use dependency injection instead 
    */ 
    @Deprecated 
    public static void setApplication(GrailsApplication application) { 
     Holders.setGrailsApplication(application); 
    } 
} 

但仍当我运行该项目,我得到这个错误:

..myapproot\target\work\plugins\excel-import-1.0.0\grails-app\services\org\grails\plugins\excelimport\ExcelImportService.groovy: 13: unable to resolve class org.codehaus.groovy.grails.commons.ApplicationHolder 
@ line 13, column 1. 
    import org.codehaus.groovy.grails.commons.ApplicationHolder 
^

1 error 

所以不知道如何我是否让excel-import插件使用这个类(因为它无法从我的应用程序使用的grails 2.4.4中找到ApplicationHolder类)?

编辑 我甚至尝试用grails命令行而不是intellij运行。同样的结果!

回答

1

So is there a way so that the org.codehaus.groovy.grails.commons.ApplicationHolder resolves to Holders.grailsApplication ?

如果你确实需要使用插件的旧版本,一个hackus-majoris将src/groovy/org/codehaus/groovy/grails/commons/ApplicationHolder.groovy(或.java)下添加自己的ApplicationHolder类。

相关问题