我想知道是否有人知道将服务注入(inject) Grails 3.X 中的自定义监听器。我正在使用 spring secuirty 插件以避免暴力攻击。除了 Grails 2.0,只有一个答案。提前致谢。
更新 !
只为那些可以使用它的人。我尝试了 Autowired 并且它有效。就像是:
@自动连线
public LoginAttemptService loginAttemptService
LoginAttemptService 已被声明为 Bean
最佳答案
如shown here
像你的注入(inject)一样声明它:
MyService myService
然后在需要的时候
def ctx = Holders.applicationContext
myService= ctx.myService
或者
def myService = Holders.grailsApplication.mainContext.getBean('myService')
如果服务需要,替代方法对于 src/main/groovy 调用特别有用
以不同的方式认为他们俩是同一件事
关于Grails 3.X 将服务注入(inject)自定义监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41687970/