Fixing the class loader issue with proxies
This commit is contained in:
@@ -25,6 +25,7 @@ import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.aop.framework.AopConfigException;
|
||||
import org.springframework.aop.framework.ProxyFactoryBean;
|
||||
import org.springframework.beans.BeansException;
|
||||
@@ -125,6 +126,10 @@ class ExecutorBeanPostProcessor implements BeanPostProcessor {
|
||||
factory.setProxyTargetClass(cglibProxy);
|
||||
factory.addAdvice(new ExecutorMethodInterceptor(executor, this.beanFactory));
|
||||
factory.setTarget(bean);
|
||||
factory.setBeanClassLoader(new ClassLoader(this.getClass().getClassLoader()) {
|
||||
|
||||
});
|
||||
factory.setBeanFactory(this.beanFactory);
|
||||
return factory.getObject();
|
||||
}
|
||||
|
||||
|
||||
@@ -79,21 +79,20 @@ public abstract class ReactorSleuth {
|
||||
// rest of the logic unchanged...
|
||||
if (beanFactory.isActive()) {
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace(
|
||||
"Spring Context [" + beanFactory + "] already refreshed. Creating a scope "
|
||||
+ "passing span subscriber with Reactor Context "
|
||||
+ "[" + sub.currentContext()
|
||||
+ "] and name [" + scannable.name()
|
||||
+ "]");
|
||||
log.trace("Spring Context [" + beanFactory
|
||||
+ "] already refreshed. Creating a scope "
|
||||
+ "passing span subscriber with Reactor Context "
|
||||
+ "[" + sub.currentContext() + "] and name ["
|
||||
+ scannable.name() + "]");
|
||||
}
|
||||
return scopePassingSpanSubscription(beanFactory, scannable,
|
||||
sub).get();
|
||||
}
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace(
|
||||
"Spring Context [" + beanFactory + "] is not yet refreshed, falling back to lazy span subscriber. Reactor Context is ["
|
||||
+ sub.currentContext() + "] and name is ["
|
||||
+ scannable.name() + "]");
|
||||
log.trace("Spring Context [" + beanFactory
|
||||
+ "] is not yet refreshed, falling back to lazy span subscriber. Reactor Context is ["
|
||||
+ sub.currentContext() + "] and name is ["
|
||||
+ scannable.name() + "]");
|
||||
}
|
||||
return new LazySpanSubscriber<T>(scopePassingSpanSubscription(
|
||||
beanFactory, scannable, sub));
|
||||
|
||||
@@ -52,7 +52,8 @@ class SpanSubscriptionProvider<T> implements Supplier<SpanSubscription<T>> {
|
||||
this.context = context;
|
||||
this.name = name;
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("Spring context [" + beanFactory + "], Reactor context [" + context + "], name [" + name + "]");
|
||||
log.trace("Spring context [" + beanFactory + "], Reactor context [" + context
|
||||
+ "], name [" + name + "]");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -73,7 +73,9 @@ public class TraceReactorAutoConfiguration {
|
||||
static HookRegisteringBeanDefinitionRegistryPostProcessor traceHookRegisteringBeanDefinitionRegistryPostProcessor(
|
||||
ConfigurableApplicationContext context) {
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("Registering bean definition registry post processor for context [" + context + "]");
|
||||
log.trace(
|
||||
"Registering bean definition registry post processor for context ["
|
||||
+ context + "]");
|
||||
}
|
||||
return new HookRegisteringBeanDefinitionRegistryPostProcessor(context);
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ public final class TraceWebFilter implements WebFilter, Ordered {
|
||||
|
||||
@Override
|
||||
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
|
||||
if (tracer().currentSpan() != null) {
|
||||
if (tracer().currentSpan() != null) {
|
||||
// clear any previous trace
|
||||
tracer().withSpanInScope(null);
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.cloud.sleuth.DefaultSpanNamer;
|
||||
import org.springframework.cloud.sleuth.SpanNamer;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
@@ -42,7 +42,9 @@ public class Issue866Configuration {
|
||||
@Bean
|
||||
HookRegisteringBeanDefinitionRegistryPostProcessor overridingProcessorForTests(
|
||||
ConfigurableApplicationContext context) {
|
||||
log.info("Registering a HookRegisteringBeanDefinitionRegistryPostProcessor for context [" + context + "]");
|
||||
log.info(
|
||||
"Registering a HookRegisteringBeanDefinitionRegistryPostProcessor for context ["
|
||||
+ context + "]");
|
||||
TestHook hook = new TestHook(context);
|
||||
Issue866Configuration.hook = hook;
|
||||
return hook;
|
||||
|
||||
@@ -281,8 +281,7 @@ public class TraceWebFluxTests {
|
||||
@RequestMapping("/test")
|
||||
static class TestEndpoint {
|
||||
|
||||
private static final Logger log = LoggerFactory
|
||||
.getLogger(TestEndpoint.class);
|
||||
private static final Logger log = LoggerFactory.getLogger(TestEndpoint.class);
|
||||
|
||||
@Autowired
|
||||
Tracer tracer;
|
||||
@@ -333,10 +332,13 @@ class SleuthSpanCreatorAspectWebFlux {
|
||||
.getLog(SleuthSpanCreatorAspectWebFlux.class);
|
||||
|
||||
private final Tracer tracer;
|
||||
|
||||
private final SleuthSpanCreatorAspectWebFlux.AccessLoggingHttpTraceRepository repository;
|
||||
|
||||
private final ArrayListSpanReporter reporter;
|
||||
|
||||
SleuthSpanCreatorAspectWebFlux(Tracer tracer, AccessLoggingHttpTraceRepository repository, ArrayListSpanReporter reporter) {
|
||||
SleuthSpanCreatorAspectWebFlux(Tracer tracer,
|
||||
AccessLoggingHttpTraceRepository repository, ArrayListSpanReporter reporter) {
|
||||
this.tracer = tracer;
|
||||
this.repository = repository;
|
||||
this.reporter = reporter;
|
||||
@@ -359,8 +361,8 @@ class SleuthSpanCreatorAspectWebFlux {
|
||||
this.reporter.clear();
|
||||
this.repository.clear();
|
||||
log.info("Running app on port [" + this.port + "]");
|
||||
this.webClient = WebTestClient.bindToServer().baseUrl("http://localhost:" + this.port)
|
||||
.build();
|
||||
this.webClient = WebTestClient.bindToServer()
|
||||
.baseUrl("http://localhost:" + this.port).build();
|
||||
}
|
||||
|
||||
public void shouldReturnSpanFromWebFluxTraceContext() {
|
||||
@@ -490,8 +492,8 @@ class SleuthSpanCreatorAspectWebFlux {
|
||||
|
||||
static class AccessLoggingHttpTraceRepository implements HttpTraceRepository {
|
||||
|
||||
private static final Log log = LogFactory
|
||||
.getLog(SleuthSpanCreatorAspectWebFlux.AccessLoggingHttpTraceRepository.class);
|
||||
private static final Log log = LogFactory.getLog(
|
||||
SleuthSpanCreatorAspectWebFlux.AccessLoggingHttpTraceRepository.class);
|
||||
|
||||
@Autowired
|
||||
Tracer tracer;
|
||||
@@ -551,8 +553,7 @@ class TestBean {
|
||||
log.info("New Span in Subscriber Context");
|
||||
Long span = tracer.currentSpan().context().spanId();
|
||||
return Mono.subscriberContext()
|
||||
.doOnSuccess(
|
||||
context -> log.info("New Span in deferred Trace Context"))
|
||||
.doOnSuccess(context -> log.info("New Span in deferred Trace Context"))
|
||||
.flatMap(context -> Mono.defer(() -> Mono.just(span)));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user