I have an abstract class that many classes extend. Everything is in src/groovy
.
In my abstract class I would like to have a service injected that the child classes would inherit so I don't have to inject them in every single one.
abstract class Animal {
def noiseService
abstract Sound getSound()
}
class Dog extends Animal {
Sound getSound() {
noiseService.bark()
}
}
In my resources.groovy:
animal(com.thepound.Animal) { bean ->
noiseService = ref("noiseService")
}
This produced an error saying it couldn't instantiate the class because it is abstract, so I added this to the definition:
bean.abstract = true
Now I no longer get an error, however the services are always null in my child classes. How can I get this to work?