Groovy conventions: where can I set metaClass definitions?

I am starting to add some Groovy classes to an existing Java web application. (This is not a Grails app)

Is there an agreement in which I should follow where I define my metaClass extensions?

In addition, I wrote several extensions to support unit tests. They are currently sitting in a @Beforebase class for tests, but I suspect there is a more obvious place that I have to set.

Any advice was greatly appreciated.

+3
source share
2 answers

- Groovy MetaClasses. (groovy.runtime.metaclass.[package].[class]MetaClass), , . . . .

+5

Grails, , grails-app/conf/BootStrap.groovy. - Java ServletContextListener, -. web.xml.

public class MetaClassInitializationListener implements ServletContextListener {
   public void contextInitialized(ServletContextEvent event) {
      // do metaClass work
   }

   public void contextDestroyed(ServletContextEvent event) {
   }
}

. JUnit, BlockJUnit4ClassRunner. , unit test , @RunWith.

0

All Articles