因爲已知在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.grailsApplication
?src/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運行。同樣的結果!