17
17
18
18
import java .lang .annotation .Annotation ;
19
19
20
- import org .springframework .beans .factory .ListableBeanFactory ;
21
20
import org .springframework .beans .factory .config .BeanDefinition ;
22
21
import org .springframework .beans .factory .support .BeanDefinitionBuilder ;
23
- import org .springframework .beans .factory .support .BeanDefinitionReaderUtils ;
24
22
import org .springframework .beans .factory .support .BeanDefinitionRegistry ;
25
23
import org .springframework .context .annotation .ImportBeanDefinitionRegistrar ;
26
24
import org .springframework .core .Ordered ;
27
25
import org .springframework .data .auditing .IsNewAwareAuditingHandler ;
28
26
import org .springframework .data .auditing .config .AuditingBeanDefinitionRegistrarSupport ;
29
27
import org .springframework .data .auditing .config .AuditingConfiguration ;
30
28
import org .springframework .data .config .ParsingUtils ;
31
- import org .springframework .data .mapping .context .PersistentEntities ;
32
29
import org .springframework .data .mongodb .core .mapping .event .AuditingEntityCallback ;
33
- import org .springframework .lang .Nullable ;
34
30
import org .springframework .util .Assert ;
35
31
36
32
/**
39
35
* @author Thomas Darimont
40
36
* @author Oliver Gierke
41
37
* @author Mark Paluch
38
+ * @author Christoph Strobl
42
39
*/
43
40
class MongoAuditingRegistrar extends AuditingBeanDefinitionRegistrarSupport implements Ordered {
44
41
@@ -55,7 +52,8 @@ protected String getAuditingHandlerBeanName() {
55
52
@ Override
56
53
protected void postProcess (BeanDefinitionBuilder builder , AuditingConfiguration configuration ,
57
54
BeanDefinitionRegistry registry ) {
58
- potentiallyRegisterMongoPersistentEntities (builder , registry );
55
+
56
+ builder .setFactoryMethod ("from" ).addConstructorArgReference ("mongoMappingContext" );
59
57
}
60
58
61
59
@ Override
@@ -87,38 +85,4 @@ protected void registerAuditListenerBeanDefinition(BeanDefinition auditingHandle
87
85
public int getOrder () {
88
86
return Ordered .LOWEST_PRECEDENCE ;
89
87
}
90
-
91
- static void potentiallyRegisterMongoPersistentEntities (BeanDefinitionBuilder builder ,
92
- BeanDefinitionRegistry registry ) {
93
-
94
- String persistentEntitiesBeanName = MongoAuditingRegistrar .detectPersistentEntitiesBeanName (registry );
95
-
96
- if (persistentEntitiesBeanName == null ) {
97
-
98
- persistentEntitiesBeanName = BeanDefinitionReaderUtils .uniqueBeanName ("mongoPersistentEntities" , registry );
99
-
100
- // TODO: https://github.com/spring-projects/spring-framework/issues/28728
101
- BeanDefinitionBuilder definition = BeanDefinitionBuilder .genericBeanDefinition (PersistentEntities .class ) //
102
- .setFactoryMethod ("of" ) //
103
- .addConstructorArgReference ("mongoMappingContext" );
104
-
105
- registry .registerBeanDefinition (persistentEntitiesBeanName , definition .getBeanDefinition ());
106
- }
107
-
108
- builder .addConstructorArgReference (persistentEntitiesBeanName );
109
- }
110
-
111
- @ Nullable
112
- private static String detectPersistentEntitiesBeanName (BeanDefinitionRegistry registry ) {
113
-
114
- if (registry instanceof ListableBeanFactory beanFactory ) {
115
- for (String bn : beanFactory .getBeanNamesForType (PersistentEntities .class )) {
116
- if (bn .startsWith ("mongo" )) {
117
- return bn ;
118
- }
119
- }
120
- }
121
-
122
- return null ;
123
- }
124
88
}
0 commit comments