From 73415d059399198124dc3f614903c9cf38c90142 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Thu, 3 May 2018 15:53:36 +0200 Subject: [PATCH] DATACMNS-1308 - Load TransactionalProxy through the provided class loader. We now load TransactionalProxy through the configured class loader for a consistent class loader usage. Loading types reflectively through the same class loader prevents visibility issues. Previously, we did not specify any class loader which defaults to the Thread's ClassLoader and which can be a different one than the configured class loader. This can cause visibility issues when implementing proxy classes as the proxy factory checks for visibilit of the particularly implemented interfaces. --- .../core/support/RepositoryFactorySupport.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/springframework/data/repository/core/support/RepositoryFactorySupport.java b/src/main/java/org/springframework/data/repository/core/support/RepositoryFactorySupport.java index b3e7819ad..1627c270a 100644 --- a/src/main/java/org/springframework/data/repository/core/support/RepositoryFactorySupport.java +++ b/src/main/java/org/springframework/data/repository/core/support/RepositoryFactorySupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2017 the original author or authors. + * Copyright 2008-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -59,12 +59,12 @@ import org.springframework.util.ObjectUtils; * detection strategy can be configured by setting {@link QueryLookupStrategy.Key}. * * @author Oliver Gierke + * @author Mark Paluch */ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware, BeanFactoryAware { private static final boolean IS_JAVA_8 = org.springframework.util.ClassUtils.isPresent("java.util.Optional", RepositoryFactorySupport.class.getClassLoader()); - private static final Class TRANSACTION_PROXY_TYPE = getTransactionProxyType(); private final Map repositoryInformationCache = new HashMap(); private final List postProcessors = new ArrayList(); @@ -205,8 +205,9 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware, result.addAdvice(SurroundingTransactionDetectorMethodInterceptor.INSTANCE); result.addAdvisor(ExposeInvocationInterceptor.ADVISOR); - if (TRANSACTION_PROXY_TYPE != null) { - result.addInterface(TRANSACTION_PROXY_TYPE); + Class transactionProxyType = getTransactionProxyType(); + if (transactionProxyType != null) { + result.addInterface(transactionProxyType); } for (RepositoryProxyPostProcessor processor : postProcessors) { @@ -383,15 +384,16 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware, } /** - * Returns the TransactionProxy type or {@literal null} if not on the classpath. + * Returns the TransactionProxy type or {@literal null} if not on the classpath. Use the provided classloader to avoid + * visibility issues. * * @return */ - private static Class getTransactionProxyType() { + private Class getTransactionProxyType() { try { return org.springframework.util.ClassUtils - .forName("org.springframework.transaction.interceptor.TransactionalProxy", null); + .forName("org.springframework.transaction.interceptor.TransactionalProxy", classLoader); } catch (ClassNotFoundException o_O) { return null; }