@@ -143,8 +143,10 @@ public class MongoTemplateTests {
143
143
144
144
@ Autowired
145
145
public void setApplicationContext (ConfigurableApplicationContext context ) {
146
- context . addApplicationListener ( new PersonWithIdPropertyOfTypeUUIDListener ());
146
+
147
147
this .context = context ;
148
+
149
+ context .addApplicationListener (new PersonWithIdPropertyOfTypeUUIDListener ());
148
150
}
149
151
150
152
@ Autowired
@@ -154,12 +156,12 @@ public void setMongo(Mongo mongo) throws Exception {
154
156
Arrays .asList (DateToDateTimeConverter .INSTANCE , DateTimeToDateConverter .INSTANCE ));
155
157
156
158
MongoMappingContext mappingContext = new MongoMappingContext ();
157
- mappingContext .setInitialEntitySet (new HashSet <Class <?>>(Arrays . asList ( PersonWith_idPropertyOfTypeObjectId . class ,
158
- PersonWith_idPropertyOfTypeString . class , PersonWithIdPropertyOfTypeObjectId .class ,
159
- PersonWithIdPropertyOfTypeString .class , PersonWithIdPropertyOfTypeInteger .class ,
160
- PersonWithIdPropertyOfTypeBigInteger .class , PersonWithIdPropertyOfPrimitiveInt .class ,
161
- PersonWithIdPropertyOfTypeLong .class , PersonWithIdPropertyOfPrimitiveLong .class ,
162
- PersonWithIdPropertyOfTypeUUID .class )));
159
+ mappingContext .setInitialEntitySet (new HashSet <Class <?>>(
160
+ Arrays . asList ( PersonWith_idPropertyOfTypeObjectId . class , PersonWith_idPropertyOfTypeString .class ,
161
+ PersonWithIdPropertyOfTypeObjectId .class , PersonWithIdPropertyOfTypeString .class ,
162
+ PersonWithIdPropertyOfTypeInteger .class , PersonWithIdPropertyOfTypeBigInteger .class ,
163
+ PersonWithIdPropertyOfPrimitiveInt .class , PersonWithIdPropertyOfTypeLong .class ,
164
+ PersonWithIdPropertyOfPrimitiveLong . class , PersonWithIdPropertyOfTypeUUID .class )));
163
165
mappingContext .setSimpleTypeHolder (conversions .getSimpleTypeHolder ());
164
166
mappingContext .initialize ();
165
167
@@ -173,8 +175,11 @@ public void setMongo(Mongo mongo) throws Exception {
173
175
174
176
@ Before
175
177
public void setUp () {
178
+
176
179
cleanDb ();
177
180
queryMongoVersionIfNecessary ();
181
+
182
+ this .mappingTemplate .setApplicationContext (context );
178
183
}
179
184
180
185
@ After
@@ -643,7 +648,6 @@ private void testProperHandlingOfDifferentIdTypes(MongoTemplate mongoTemplate) t
643
648
PersonWithIdPropertyOfTypeUUID p13 = new PersonWithIdPropertyOfTypeUUID ();
644
649
p13 .setFirstName ("Sven_10" );
645
650
p13 .setAge (22 );
646
- p13 .setId (UUID .randomUUID ());
647
651
// insert
648
652
mongoTemplate .insert (p13 );
649
653
// also try save
@@ -3609,10 +3613,12 @@ static class WithObjectTypeProperty {
3609
3613
Object value ;
3610
3614
}
3611
3615
3612
- static class PersonWithIdPropertyOfTypeUUIDListener extends AbstractMongoEventListener <PersonWithIdPropertyOfTypeUUID > {
3616
+ static class PersonWithIdPropertyOfTypeUUIDListener
3617
+ extends AbstractMongoEventListener <PersonWithIdPropertyOfTypeUUID > {
3613
3618
3614
3619
@ Override
3615
3620
public void onBeforeConvert (BeforeConvertEvent <PersonWithIdPropertyOfTypeUUID > event ) {
3621
+
3616
3622
PersonWithIdPropertyOfTypeUUID person = event .getSource ();
3617
3623
3618
3624
if (person .getId () != null ) {
@@ -3621,6 +3627,5 @@ public void onBeforeConvert(BeforeConvertEvent<PersonWithIdPropertyOfTypeUUID> e
3621
3627
3622
3628
person .setId (UUID .randomUUID ());
3623
3629
}
3624
-
3625
3630
}
3626
3631
}
0 commit comments