Skip to content

Commit 2d96f76

Browse files
committed
grails/grails-data-hibernate5#202 Update DatastoreServiceMethodInvokingFactoryBean
to configure autowire by type.
1 parent b969c47 commit 2d96f76

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/config/DatastoreServiceMethodInvokingFactoryBean.groovy

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import groovy.transform.CompileStatic
44
import groovy.transform.Internal
55
import org.grails.datastore.mapping.core.Datastore
66
import org.grails.datastore.mapping.services.Service
7+
import org.springframework.beans.factory.BeanFactory
8+
import org.springframework.beans.factory.config.AutowireCapableBeanFactory
9+
import org.springframework.beans.factory.config.ConfigurableBeanFactory
710
import org.springframework.beans.factory.config.MethodInvokingFactoryBean
11+
import org.springframework.lang.Nullable
812

913
/**
1014
* Variant of {#link MethodInvokingFactoryBean} which returns the correct data service type instead of {@code java.lang.Object} so the Autowire with type works correctly.
@@ -13,6 +17,9 @@ import org.springframework.beans.factory.config.MethodInvokingFactoryBean
1317
@CompileStatic
1418
class DatastoreServiceMethodInvokingFactoryBean extends MethodInvokingFactoryBean {
1519

20+
@Nullable
21+
private ConfigurableBeanFactory beanFactory
22+
1623
@Override
1724
Class<?> getObjectType() {
1825
arguments[0] as Class<?>
@@ -23,7 +30,18 @@ class DatastoreServiceMethodInvokingFactoryBean extends MethodInvokingFactoryBea
2330
Object object = super.invokeWithTargetException()
2431
if (object) {
2532
((Service) object).setDatastore((Datastore) targetObject)
33+
if (beanFactory instanceof AutowireCapableBeanFactory) {
34+
((AutowireCapableBeanFactory) beanFactory).autowireBean(object)
35+
}
2636
}
2737
object
2838
}
39+
40+
@Override
41+
void setBeanFactory(BeanFactory beanFactory) {
42+
super.setBeanFactory(beanFactory)
43+
if (beanFactory instanceof ConfigurableBeanFactory) {
44+
this.beanFactory = (ConfigurableBeanFactory) beanFactory
45+
}
46+
}
2947
}

0 commit comments

Comments
 (0)