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

  • Home
  • SEARCH
  • 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 640491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:57:32+00:00 2026-05-13T20:57:32+00:00

I’m trying to intercept a method call (afterInsert() of a domain class) in a

  • 0

I’m trying to intercept a method call (afterInsert() of a domain class) in a Grails application. In doWithDynamicMethods closure of my plugin I have:

for (dc in application.domainClasses) {
    // What I'm basically doing is renaming method A to B
    // and creating a new method A with its own business logic
    // and a call to B() at the end

    def domainClass = dc.getClazz()
    def oldAfterInsert = domainClass.metaClass.afterInsert
    domainClass.metaClass."afterInsert_old" = oldAfterInsert

    dc.metaClass.afterInsert = {
        // New afterInsert() logic here

        // Call the old after insert
        delegate.afterInsert_old()
    }

}

But then I get this error:

No signature of method: static com.example.afterInsert_old() is applicable for argument types: () values: []

I’ve also tried to call it with dc.metaClass.”afterInsert_old”.invoke(delegate, new Object[0]) but then I get:

Caused by: groovy.lang.MissingMethodException: No signature of method: groovy.lang.ExpandoMetaClass$ExpandoMetaProperty.invoke() is applicable for argument types: (com.example.DomainName, [Ljava.lang.Object;) values: [com.example.DomainName : 115, []]

What am I doing wrong? How can I call a method that takes no arguments?

I know about AOP and have also seen the Grails Audit Logging plugin as an example. However, what it does is, as far as I know, add new user created methods that get triggered at the right time. I want to inject my code automatically so that the user doesn’t have to worry about anything and I don’t want to destroy his original afterInsert() (or whatever method it is) implementation.

Also, I’d like to do the same for exposed service methods in order to inject security into them. However, from what I’ve read it would not work because of the BeanWrapper and because the services are always reloaded. Can someone explain this better to me?

Thanks in advance.

  • 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-13T20:57:32+00:00Added an answer on May 13, 2026 at 8:57 pm

    I don’t think you need to rename the old method. You could do it like in this example:

    for (dc in application.domainClasses) {
        // What I'm basically doing is renaming method A to B
        // and creating a new method A with its own business logic
        // and a call to B() at the end
        def domainClass = dc.getClazz()
        def savedAfterInsert = domainClass.metaClass.getMetaMethod('afterInsert', [] as Class[])
        domainClass.metaClass.afterInsert = {
            // New afterInsert() logic here
    
            // Call the old after insert
            savedAfterInsert.invoke(delegate)
        }
    
    }
    

    Just make sure that the getMetaMethod returns the correct method.

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

Sidebar

Related Questions

No related questions found

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.