1

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?

Anonymous1
  • 3,877
  • 3
  • 28
  • 42
  • 2
    How are you defining the `service`? The provided code snippet is not sufficient. – Adeel Ansari Mar 28 '17 at 07:28
  • Along with that provide the directory structure as well, if you are following the conventions right, then it should work. "Grails 3.2.8 doesn't seem to have dependency injection working for domain classes by default." is probably a wrong generalization. For my app, 3.2.6 Grails works alright. – Tyagi Akhilesh Mar 28 '17 at 10:16

1 Answers1

4

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

erichelgeson
  • 2,310
  • 1
  • 16
  • 24