我完全同意John的观点-在服务中执行GSP通常是一个错误的设计决策。但是没有规则没有例外!如果仍然要执行此操作,请尝试以下方法:
class MyService implements InitializingBean { boolean transactional = false def gspTagLibraryLookup // being automatically injected by spring def g public void afterPropertiesSet() { g = gspTagLibraryLookup.lookupNamespaceDispatcher("g") assert g } def serviceMethod() {// do anything with e.g. g.render }}当然,使用gspTagLibraryLookup bean,您可以访问服务中所有其他所需的taglib。



