Grails - 无法从控制器调用服务 - >总是得到“不能在空对象错误上调用方法” [英] Grails - Can't call service from Controller --> always get "Cannot invoke method on null object error"
问题描述
我有一个grails应用程序,我在这里遵循教程:
http:/ /www.grails.org/Services
i have a grails application and i'm following the tutorial here:
http://www.grails.org/Services
我有一些代码
import org.springframework.beans.factory.InitializingBean
class SubmitRequestService implements InitializingBean{
def GrailsApplication1
def setting
void afterPropertiesSet(){
this.setting = GrailsApplication1.config.setting
}
def void sendHistoricalContract(HistoricalContract hc_instance){
//... blah blah whatever code
}
}
class SubmitRequestController {
def submitRequestService
static allowedMethods = [save: "POST", update: "POST", delete: "POST"]
def index = {
// .... blah blah whatever code
submitRequestService.sendHistoricalContract(historicalContractInstance)
}
}
无论我做什么,我似乎无法获得服务注入到控制器。每当我到达我调用服务的行,我得到的错误:
No whatever i do, i can't seem to get the service to be injected into the controller. Whenever I get to the line where i call the service i get the error:
ERROR errors.GrailsExceptionResolver - 无法调用sendHistoricalContract null对象
ERROR errors.GrailsExceptionResolver - Cannot invoke method sendHistoricalContract() on null object
我做错了什么?
/ p>
Thanks in advance
推荐答案
Burt的答案是有帮助的(+1到Burt),但是如果其他人遵循这里的教程:
http://www.grails.org/Services
并体验相同的问题我有,我想让它明确:
Burt's answer is helpful (+1 to Burt) but in case others are following the tutorial here:
http://www.grails.org/Services
and experiencing the same issue i had, i want to make it explicit:
服务进入自己的文件在
的服务目录,你做不是
结合他们与控制器,甚至
虽然它看起来像在代码
示例
Services go in their own files under the Services directory, you do not combine them with controllers, even though it looks that way in the code examples
请参阅上面关于服务和Spring框架的其他资源的Burt的评论。
See Burt's comment above on additional resources to Services and the Spring Framework.
这篇关于Grails - 无法从控制器调用服务 - >总是得到“不能在空对象错误上调用方法”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!