2011-11-19 57 views
2

我的Grails应用程序中有一个NotificationsAtmosphereHandler作为Atmosphere框架处理程序类。我想在里面使用springSecurityService服务。我如何将服务对象注入到处理程序类中?向Grails氛围处理程序类注入服务

def springSecurityService 

通常的服务注入不起作用。

回答

2

resources.xml中:

<bean id="notificationsAtmosphereHandler" class="your.package.NotificationsAtmosphereHandler"/> 

类:

class NotificationsAtmosphereHandler { 
    ..... 
    @Autowired 
    SpringSecurityService springSecurityService 
    ..... 
} 
+1

它不起作用的根本原因是您的NotificationsAtmosphereHandler未被Grails识别为应该管理和实例化的bean。 (这不是服务或控制器)。因此,您需要像在此答案中配置其实例化 –

+0

您能解释如何在grails 2.2.1中执行此操作吗? –

0

或者说做你resources.groovy Groovy的方式:

import package.NotificationsAtmosphereHandler 

//... 

notificationsAtmosphereHandler(NotificationsAtmosphereHandler) { bean -> 
    bean.autowire = 'byName' 
} 

这样,你不还需要@Autowired符号。