2017-07-01 84 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類。

相關問題