Groovy是否提供了包含机制? [英] Does groovy provide an include mechanism?

查看:180
本文介绍了Groovy是否提供了包含机制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在我的例子中,我们有web服务端点作为groovy脚本并希望登录到我们的Web服务协议。为此,我们使用隐式对象(从我们的框架中获取)来创建日志记录语句。



但是,如果我们在每个Web服务端点中编写代码,这就是样板代码。 / p>

我们正在寻找像include()这样的东西,其中包括其他常用脚本,有没有想法如何做到这一点?


<由于你已经提到过交叉关注,所以我想说你需要拦截你的web服务调用

解决方案

AOP 风格(不是包含机制)。

Grails与 Spring框架,所以这使得这是开发Spring AOP特性的一个很好的选择。看看grails官方指南中的这一章:
http://grails.org/doc/latest/guide/14.%20Grails%20and%20Spring.html 并搜索单词AOP。



也许有一种做AOP的纯粹的常规方式,但我会去与grails和春天。


We are searching for an include mechanism for groovy scripts to have space for cross-cutting-concerns.

In my example we have, web service endpoints as groovy scripts and want to log to our web service protocol. for that we use our implicit object (getting from our framework) to create the logging statement.

But this is boilerplate code if we code this in every web service endpoint.

We are searching for something like include() in php, that includes other groovy scripts, are there any ideas how to do this?

解决方案

Since you already mentioned "cross-cutting-concerns" I’d say that you need to intercept your webservice calls AOP style (not an include mechanism).

Grails is completely integrated with Spring framework, so this makes for a good option for exploiting Spring AOP features. Take a look at this chapter from grails official guide: http://grails.org/doc/latest/guide/14.%20Grails%20and%20Spring.html and search for word AOP.

Maybe there is a purely groovy way of doing AOP, but I'd go with grails and spring.

这篇关于Groovy是否提供了包含机制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆