Skip to content

Commit 8fdedcf

Browse files
committed
Merge remote-tracking branch 'origin/4.0.x'
2 parents 8cfb8e3 + 6ce1deb commit 8fdedcf

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

spring-cloud-context/src/main/java/org/springframework/cloud/context/named/NamedContextFactory.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -158,27 +158,27 @@ public void registerBeans(String name, GenericApplicationContext context) {
158158
}
159159

160160
public GenericApplicationContext buildContext(String name) {
161+
// https://github.com/spring-cloud/spring-cloud-netflix/issues/3101
162+
// https://github.com/spring-cloud/spring-cloud-openfeign/issues/475
163+
ClassLoader classLoader = getClass().getClassLoader();
161164
GenericApplicationContext context;
162165
if (this.parent != null) {
163-
// jdk11 issue
164-
// https://github.com/spring-cloud/spring-cloud-netflix/issues/3101
165-
// https://github.com/spring-cloud/spring-cloud-openfeign/issues/475
166166
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
167167
if (parent instanceof ConfigurableApplicationContext) {
168168
beanFactory.setBeanClassLoader(
169169
((ConfigurableApplicationContext) parent).getBeanFactory().getBeanClassLoader());
170170
}
171171
else {
172-
beanFactory.setBeanClassLoader(parent.getClassLoader());
172+
beanFactory.setBeanClassLoader(classLoader);
173173
}
174174
context = AotDetector.useGeneratedArtifacts() ? new GenericApplicationContext(beanFactory)
175175
: new AnnotationConfigApplicationContext(beanFactory);
176-
context.setClassLoader(parent.getClassLoader());
177176
}
178177
else {
179178
context = AotDetector.useGeneratedArtifacts() ? new GenericApplicationContext()
180179
: new AnnotationConfigApplicationContext();
181180
}
181+
context.setClassLoader(classLoader);
182182
context.getEnvironment().getPropertySources().addFirst(
183183
new MapPropertySource(this.propertySourceName, Collections.singletonMap(this.propertyName, name)));
184184
if (this.parent != null) {

0 commit comments

Comments
 (0)