Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to adding Dynamic Methods at Runtime to Grails domain object without creating plugins?

In the ref documentation I found only example such as

class ExamplePlugin {
  def doWithDynamicMethods = { applicationContext ->
        application.controllerClasses.each { controllerClass ->
             controllerClass.metaClass.myNewMethod = {-> println "hello world" }
        }
  }
}

But I don't want to create plugin for such code...

like image 425
yura Avatar asked May 26 '26 00:05

yura


1 Answers

You can add your dynamic methods in the grails-app/conf/BootStrap.groovy file in the init closure, then they should be available at app startup.

Note that the dynamic methods you add this way won't be available in your unit tests. They will be available in integration tests and at run-time.

like image 52
John Wagenleitner Avatar answered May 30 '26 02:05

John Wagenleitner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!