이것은 다소 이상한 문제이며 잠시 동안 그 문제에 빠졌습니다.springSecurityService는 기본 컨트롤러에서 null입니다.
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'속성을 가져올 수 없습니다. 에 null 개체가 있습니다. com.ticketbranch.EventAwareController.getAuthorizedEventById (EventAwareController.groovy : 14)
하지만 EventController의 내 prinln 문은 프린시 펄 ID를 아무런 문제없이 인쇄합니다. 그래서 springSecurityService는 EventAwareController에서 null로 주입됩니까?
아이디어가 있으십니까? 제안? 감사.
아, 이해해 주셔서 감사합니다. – Micor
매우 멋진 답변, 무슨 일이 일어나는지 이해하려고 애쓰는 데 시간을 보냈습니다 ... 무슨 일이 벌어지고 있는지 이해하도록 도와 주셔서 감사합니다. :) –