@@ -19,11 +19,7 @@ import org.grails.datastore.mapping.services.ServiceDefinition
1919import org.grails.datastore.mapping.services.SoftServiceLoader
2020import org.grails.datastore.mapping.transactions.DatastoreTransactionManager
2121import org.springframework.beans.factory.support.BeanDefinitionRegistry
22- import org.springframework.context.ApplicationContext
23- import org.springframework.context.ApplicationEventPublisher
24- import org.springframework.context.ConfigurableApplicationContext
25- import org.springframework.context.MessageSource
26- import org.springframework.context.ResourceLoaderAware
22+ import org.springframework.context.*
2723import org.springframework.context.support.GenericApplicationContext
2824import org.springframework.context.support.StaticMessageSource
2925import org.springframework.core.env.ConfigurableEnvironment
@@ -294,7 +290,7 @@ abstract class AbstractDatastoreInitializer implements ResourceLoaderAware{
294290 datastore = ref(" ${ type} Datastore" )
295291 }
296292 }
297- loadDataServices (null )
293+ loadServices (null )
298294 .each {serviceName , serviceClass ->
299295 " $serviceName " (DatastoreServiceMethodInvokingFactoryBean ) {
300296 targetObject = ref(" ${ type} Datastore" )
@@ -306,35 +302,37 @@ abstract class AbstractDatastoreInitializer implements ResourceLoaderAware{
306302 }
307303
308304 @CompileDynamic
309- protected Map<String , Class<?> > loadDataServices (String secondaryDatastore = null ) {
310- Map<String , Class<?> > dataServices = [:]
311- final SoftServiceLoader<Service > services = SoftServiceLoader . load(Service )
312- for (ServiceDefinition<Service > serviceDefinition : services ) {
305+ protected Map<String , Class<?> > loadServices (String secondaryDatastore = null ) {
306+ Map<String , Class<?> > services = [:]
307+ final SoftServiceLoader<Service > softServiceLoader = SoftServiceLoader . load(Service )
308+ for (ServiceDefinition<Service > serviceDefinition : softServiceLoader ) {
313309 if (serviceDefinition. isPresent()) {
314310 final Class<Service > clazz = serviceDefinition. getType()
315- if (clazz. simpleName. startsWith(' $' ) && clazz. simpleName. endsWith(' Implementation' )) {
316- Class<?> serviceClass = loadServiceClass(clazz)
317- final grails.gorm.services.Service ann = clazz. getAnnotation(grails.gorm.services.Service )
318- String serviceName = ann?. name()
319- if (serviceName == null ) {
320- serviceName = Introspector . decapitalize(serviceClass. simpleName)
321- }
322- if (secondaryDatastore) {
323- serviceName = secondaryDatastore + NameUtils . capitalize(serviceName)
324- }
325- if (serviceClass != null && serviceClass != Object . class) {
326- dataServices. put(serviceName, serviceClass)
327- }
311+ final Class<?> serviceClass = loadServiceClass(clazz)
312+ final grails.gorm.services.Service ann = clazz. getAnnotation(grails.gorm.services.Service )
313+ String serviceName = ann?. name()
314+ if (serviceName == null ) {
315+ serviceName = Introspector . decapitalize(serviceClass. simpleName)
316+ }
317+ if (secondaryDatastore) {
318+ serviceName = secondaryDatastore + NameUtils . capitalize(serviceName)
319+ }
320+ if (serviceClass != null && serviceClass != Object . class) {
321+ services. put(serviceName, serviceClass)
328322 }
329323 }
330324 }
331- return dataServices;
325+ return services
332326 }
333327
334328 private Class<?> loadServiceClass (Class<Service > clazz ) {
335- final String serviceClassName = clazz. package. getName() + ' .' + clazz. simpleName[1 .. -15 ]
336- final Class<?> serviceClass = classLoader. loadClass(serviceClassName)
337- serviceClass
329+ if (clazz. simpleName. startsWith(' $' ) && clazz. simpleName. endsWith(' Implementation' )) {
330+ final String serviceClassName = clazz. package. getName() + ' .' + clazz. simpleName[1 .. -15 ]
331+ final Class<?> serviceClass = classLoader. loadClass(serviceClassName)
332+ serviceClass
333+ } else {
334+ clazz
335+ }
338336 }
339337
340338 @CompileDynamic
0 commit comments