【发布时间】:2011-11-28 04:22:06
【问题描述】:
这是一个相当奇怪的问题,我已经解决了一段时间,所以我要疯了。
我有一个控制器扩展了另一个控制器,所以我可以让多个控制器继承一个方法,它们会像这样:
class EventController extends EventAwareController {
def springSecurityService
def edit = {
// this line prints out principal id
println springSecurityService.principal.id
def eventInstance = getAuthorizedEventById(params.id)
if (!eventInstance) {
flash.message = "${message(code: 'event.not.found.message')}"
redirect(action: "list", controller: "event")
return false
}
}
class EventAwareController {
def eventService
def springSecurityService
def getAuthorizedEventById(def eventId) {
def event
if (eventId) {
// this springSecurityService is null and throws an error
event = eventService.findAuthorizedEvent(eventId, springSecurityService.principal.id)
if (event) {
session.eventId = eventId
}
}
return event
}
}
EventAwareController 正在抛出:
java.lang.NullPointerException: 无法获取属性'principal' on 空对象在 com.ticketbranch.EventAwareController.getAuthorizedEventById(EventAwareController.groovy:14)
但是我在 EventController 中的 prinln 语句打印主体 ID 没有任何问题?!?那么springSecurityService在EventAwareController中被注入为null?
有什么想法吗?建议?谢谢。
【问题讨论】: