views:

387

answers:

3

What if you don't want to start a separate project for grails but instead sneak it into an existing webapp?

I have to build an admin interface/crud for some new entities and thought it would be a perfect way to learn grails.

A: 

It would be hard to "sneak it in" unless the existing app has the correct dir structure that maps exactly to how grails likes it - after all, convention over config is where the power of grails comes from.

You can try doing the admin interface as a "seperate" app to the original/existing spring app, and map the existing database to the grails domain objects. though i m not sure how you would run them side by side easily without more information on the existing app. It is possible definitely though.

Chii
One problem with putting the admin for the entities in a separate app would be an invalid L2 cache in the main app. A solution to this could be to create some mechanism in the admin app that calls some cache invalidation service on the main app or to share a distributed cache. I hoped for a simpler solution so that the grails part and the spring part of the app could share cache and state.
D. Wroblewski
Would it affect performance badly if you disabled the L2 cache?
Andrew Swan
not sure about the L2 cache. try it and see?
Chii
A: 

I agree that building your admin interface is a good exercise to learn Grails, and also agree with the previous answer that Grails is difficult if not impossible to integrate with an existing Spring application. You could probably get it done, but the headache would not be worth it.

Grails is built on top of Hibernate for its ORM, so if you're already using Hibernate with this Spring app you can work this to your advantage. It's not too difficult to configure a Grails app to use pre-existing Hibernate models, and this is explained well in Grails documentation.

So, I'd recommend building up your admin console as an independent Grails app but make use of the Hibernate models you already have, if in fact you've used Hibernate.

+2  A: 

I'm trying to make one application with a Grails app and a Spring app.

I've tried to sneak the Grails App into the Spring one, but this is "impossible". It's easier to sneak the Spring app into the Grails app. Grails knows what Spring is, but Spring has no idea of what Grails is.

In this article you can find useful information about how to use your hibernate mapping files or annotations in Grails, so you don't have to remap everything. Also you can use all your java clases (put them into src/java). You can put the beans defined in the ApplicationContext.xml in conf/spring/resources.xml. You can leave them in ApplicationContext, but I've had some problems. I don't have ended the job (almost) and it looks good.

HED