我确认在确认插件安装正确后尝试使用此Grails插件中定义的方法:
对于我可以推测的所有内容,我在我的Controller中添加以下导入行:
import grails.plugin.openexchangerates
但编译器一直在唠叨它无法解析该类。 我尝试了以下所有组合但无济于事:
grails.plugin.openexchangerates.*
services.grails.plugin.openexchangerates
services.grails.plugin.openexchangerates.*
等
我在这里错过了什么明显的事情?
答案 0 :(得分:1)
它没有导入Grails插件,顺便说一下。只是标准(groovy / java / jvm)导入,但是对于来自grails插件的类,它是一种非常常见的情况。
这个班级有package grails.plugin.openexchangerates
,所以你可以这样做:
import grails.plugin.openexchangerates.*
或
import grails.plugin.openexchangerates.OpenExchangeRatesService
但请确保将插件添加到依赖项中,添加到BuildConfig
中,作为
compile ':open-exchange-rates:0.1'
插件自述文件建议使用runtime ':open-exchange-rates:0.1'
,但在这种情况下编译器在类路径中没有插件类。您需要使用compile
范围。查看有关依赖范围的更多信息:http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope