2011-11-19 2 views
2

Grails 애플리케이션에 Atmosphere 프레임 워크 핸들러 클래스로 NotificationsAtmosphereHandler가 있습니다. 그 안에 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에서 그루비 방식으로 수행

import package.NotificationsAtmosphereHandler 

//... 

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

이 방법, 당신이 돈을 @Autowired 표기법도 필요하지 않습니다.

관련 문제