Grails 3.2.8 dependency injection in domain classes

◇◆丶佛笑我妖孽 提交于 2019-12-11 07:12:16

问题


Grails 3.2.8 doesn't seem to have dependency injection working for domain classes by default.

When I create a new app and add Spring Security Core 3.1.1 with the following println:

protected void encodePassword() {
    println "springSecurityService == null? ${(springSecurityService==null).toString()}"
    password = springSecurityService?.passwordEncoder ? springSecurityService.encodePassword(password) : password
}

I get:

springSecurityService == null? true

If I try creating and injecting a service similarly, I get the same null value. Is there a good workaround?


回答1:


Starting with Grails 3.2.8 autowiring of domain classes is disabled by default for performance reasons. You can re-enable it by setting grails.gorm.autowire = true

Grame has mentioned a patch for spring-security-core to work around needing the service injection is coming, in the meantime just re-enable autowiring.

See my unofficial changelog on 3.2.8 here: https://gist.github.com/erichelgeson/be2f9f62ab63d989f2ec962ae7001f21



来源:https://stackoverflow.com/questions/43059313/grails-3-2-8-dependency-injection-in-domain-classes

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