On a previous project we used different classes for the beans depending on an environment variable. There we start with the service interface to find the implementation class we want to use based on a naming convention, as shown in the code snippet below.
The only difference with your code is that we use the classloader of the service interface to retrieve the implementation class. Another option is ofcourse that grailsApplication.config.foo.bar does not contain a correct value.
In the grails-app/conf/spring directory our beans file contained the following code to load the correct implementation class:
beans = {
addressService(getImplementation(AddressService))
appointmentService(getImplementation(AppointmentService))
}
def getImplementation(Class service) {
if (CH.config.mockAllServices == 'true' || CH.config."mock${service.simpleName}" == 'true') {
return service.classLoader.loadClass(service.name + 'Mock')
}
return service.classLoader.loadClass(service.name + 'Impl')
}