众所周知,在{2.}} 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文件夹中创建了一个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 (marc@anyware.co.uk)
*
* @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运行。结果相同!
答案 0 :(得分:1)
那么有没有办法让... org.codehaus.groovy.grails.commons.ApplicationHolder解析为 Holders.grailsApplication?
如果您确实需要使用旧版本的插件,那么一个hackus-majoris就是在ApplicationHolder
(或src/groovy/org/codehaus/groovy/grails/commons/ApplicationHolder.groovy
)下添加您自己的.java
课程。