Injecting service into Grails Atmosphere Handler class

China☆狼群 提交于 2019-12-11 00:36:29

问题


I have an NotificationsAtmosphereHandler as an Atmosphere framework handler class in my Grails application. I would like to use springSecurityService service inside of it. How I can inject service object into my handler class?

def springSecurityService

The usual service injection does not work.


回答1:


resources.xml:

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

in class:

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



回答2:


or rather do it the Groovy way in your resources.groovy:

import package.NotificationsAtmosphereHandler

//...

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

this way, you don't need the @Autowired notation also.



来源:https://stackoverflow.com/questions/8196928/injecting-service-into-grails-atmosphere-handler-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!