kiRach
kiRach

Reputation: 2455

Grails: what is the best way to use GORM directly from src/java?

In my grails application I have Java classes (src/java). And I want to have access to my domain classes and use GORM features(like get(), findBy..., save(), delete() and etc.) directly from my Java classes. I know, I can do this by Spring IoC: for example, I can add grails service to my Java class:

public class SimpleJavaClass{

    //...    

    @Autowired
    private ExampleService exampleService;

    //...
}

And wireup each instance of this class by Spring:

//...

GrailsApplication grailsApplication

//...

def simpleAction(){
    def instance = new SimpleJavaClass()
    grailsApplication.mainContext.autowireCapableBeanFactory.autowireBean(instance)
}

But may be there is more appropriate way to do same?

Upvotes: 1

Views: 834

Answers (1)

Graeme Rocher
Graeme Rocher

Reputation: 7985

Using Grails 2.0, the only current way is to package your domain classes into a binary plugin (see http://grails.org/doc/2.0.x/guide/single.html#binaryPlugins)

You then can depend on this binary plugin and because it is precompiled the Java code will see many of the GORM methods which are wired into the byte code

Upvotes: 4

Related Questions