Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6659013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:58:52+00:00 2026-05-26T01:58:52+00:00

This is a rather weird problem and I been at it for a while

  • 0

This is a rather weird problem and I been at it for a while so I am going nuts.

I have a controller extending another controller so I can have multiple controllers inheriting a method and they go something like this:

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 is throwing:

java.lang.NullPointerException: Cannot get property ‘principal’ on
null object at
com.ticketbranch.EventAwareController.getAuthorizedEventById(EventAwareController.groovy:14)

but my prinln statement in EventController prints principal id without any issues?!? So springSecurityService is injected as null in EventAwareController?

Any ideas? suggestions? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:58:53+00:00Added an answer on May 26, 2026 at 1:58 am

    You have the field in both classes, and this is a problem when using Groovy. Dependency injection in Grails is typically done like you’re doing, with def <beanname>. This is a public field, so Groovy creates a public getter and setter for it and makes the field private. The getter isn’t used, but Spring sees the setter and since beans are configured to be wired by name (as opposed to by type) the bean is injected since there’s a match between the setter name (setSpringSecurityService) and the bean name.

    Since you have this twice, you have two setters and one wins, so you’ll have a null value for the private field in one class.

    But like any public (or protected) property the dependency injection is inherited, so just remove it from all of your subclasses and leave it in the base class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been having this rather frustrating problem, and having failed so many times, I'm
i have a rather weird problem that should fix a bug in my current
I have a rather weird problem. Because of a certain PECL bug , I
I have run into a rather weird little problem. In the following code I
I have run into a rather weird problem. I have created the following query
I came about a rather weird problem today. I have a math library optimized
I most likely have the same problem as in this question: Weird Chrome prototype/jQuery
I have a rather weird problem with a control that doesn't want to resize.
I know this is rather laughable, but I can't seem to get simple C++
This may be rather noobish but I'm gonna ask anyhow. I have a class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.