Accessing Grails services from src/groovy

前端 未结 3 876
伪装坚强ぢ
伪装坚强ぢ 2021-01-21 08:11

Grails services are abstractions used for implementing business logic (as well as connecting to backing services/DBs, etc.) outside of a controller. So in a typical controller y

3条回答
  •  清歌不尽
    2021-01-21 08:40

    One way of achieving this is by using ServletContext-

    ApplicationContext ctx = (ApplicationContext)ServletContextHolder.
    
    getServletContext().getAttribute(GrailsApplicationAttributes.APPLICATION_CONTEXT)
    
    statisticsService = (StatisticsService ) ctx.getBean("statisticsService ")
    

    see this blog - http://www.grailsbrains.com/availing-grails-goodies-in-srcjava-or-srcgroovy/

提交回复
热议问题