简体   繁体   English

将grails集成到现有的spring应用程序中?

[英]Integrating grails into an existing spring application?

What if you don't want to start a separate project for grails but instead sneak it into an existing webapp? 如果您不想为Grails启动一个单独的项目而是将其潜入现有的Webapp中怎么办?

I have to build an admin interface/crud for some new entities and thought it would be a perfect way to learn grails. 我必须为一些新实体构建一个管理界面/对象,并认为这是学习grails的理想方法。

I'm trying to make one application with a Grails app and a Spring app. 我正在尝试使用Grails应用程序和Spring应用程序制作一个应用程序。

I've tried to sneak the Grails App into the Spring one, but this is "impossible". 我试图将Grails应用程序潜入春季应用程序,但这是“不可能的”。 It's easier to sneak the Spring app into the Grails app. 将Spring应用程序潜入Grails应用程序更容易。 Grails knows what Spring is, but Spring has no idea of what Grails is. Grails知道Spring是什么,但是Spring不知道Grails是什么。

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. 文章中,你可以找到有关如何使用Hibernate映射文件或注解Grails的,所以你不必重新映射一切有用的信息。 Also you can use all your java clases (put them into src/java). 您也可以使用所有Java分类(将它们放入src / java)。 You can put the beans defined in the ApplicationContext.xml in conf/spring/resources.xml. 您可以将在ApplicationContext.xml中定义的bean放在conf / spring / resources.xml中。 You can leave them in ApplicationContext, but I've had some problems. 您可以将它们留在ApplicationContext中,但是我遇到了一些问题。 I don't have ended the job (almost) and it looks good. 我还没有结束工作(差不多),看起来还不错。

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. 除非现有的应用程序具有正确的目录结构以准确地映射到grails的喜欢程度,否则很难“潜入它”-毕竟,grails的强大功能来自于config上的约定。

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. 您可以尝试将管理界面作为原始/现有spring应用程序的“单独”应用程序进行处理,并将现有数据库映射到grails域对象。 though im not sure how you would run them side by side easily without more information on the existing app. 尽管我不确定在没有现有应用程序更多信息的情况下如何轻松地并行运行它们。 It is possible definitely though. 当然有可能。

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. 我同意构建您的管理界面是学习Grails的一个好习惯,并且也同意前面的回答,即Grails很难(即使不是不可能)与现有的Spring应用程序集成也是困难的。 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. Grails的ORM基于Hibernate构建,因此,如果您已经在此Spring应用程序中使用了Hibernate,则可以利用它来发挥自己的优势。 It's not too difficult to configure a Grails app to use pre-existing Hibernate models, and this is explained well in Grails documentation. 配置Grails应用程序以使用预先存在的Hibernate模型并不是很困难,这在Grails文档中得到了很好的解释。

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. 因此,我建议将您的管理控制台构建为一个独立的Grails应用程序,但要使用您已经拥有的Hibernate模型(如果您实际上已经使用过Hibernate)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM