Skip to content

Commit cf4e04a

Browse files
christophstroblmp911de
authored andcommitted
DATAMONGO-2547 - Use target class ClassLoader instead of default CL when creating proxy instances.
Original pull request: #865.
1 parent 89c1dc7 commit cf4e04a

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoDatabaseFactorySupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ private <T> T createProxyInstance(com.mongodb.session.ClientSession session, T t
254254
factory.addAdvice(new SessionAwareMethodInterceptor<>(session, target, ClientSession.class, MongoDatabase.class,
255255
this::proxyDatabase, MongoCollection.class, this::proxyCollection));
256256

257-
return targetType.cast(factory.getProxy());
257+
return targetType.cast(factory.getProxy(target.getClass().getClassLoader()));
258258
}
259259
}
260260
}

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/SimpleReactiveMongoDatabaseFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ private <T> T createProxyInstance(com.mongodb.session.ClientSession session, T t
266266
factory.addAdvice(new SessionAwareMethodInterceptor<>(session, target, ClientSession.class, MongoDatabase.class,
267267
this::proxyDatabase, MongoCollection.class, this::proxyCollection));
268268

269-
return targetType.cast(factory.getProxy());
269+
return targetType.cast(factory.getProxy(target.getClass().getClassLoader()));
270270
}
271271
}
272272
}

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DefaultDbRefResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ private Object createLazyLoadingProxy(MongoPersistentProperty property, @Nullabl
202202
proxyFactory.addInterface(propertyType);
203203
proxyFactory.addAdvice(interceptor);
204204

205-
return handler.populateId(property, dbref, proxyFactory.getProxy());
205+
return handler.populateId(property, dbref, proxyFactory.getProxy(LazyLoadingProxy.class.getClassLoader()));
206206
}
207207

208208
/**

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/QueryUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static Query decorateSort(Query query, Document defaultSort) {
6161
return combinedSort;
6262
});
6363

64-
return (Query) factory.getProxy();
64+
return (Query) factory.getProxy(query.getClass().getClassLoader());
6565
}
6666

6767
/**

0 commit comments

Comments
 (0)