|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2020 the original author or authors. |
| 2 | + * Copyright 2012-2023 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -158,27 +158,27 @@ public void registerBeans(String name, GenericApplicationContext context) {
|
158 | 158 | }
|
159 | 159 |
|
160 | 160 | 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(); |
161 | 164 | GenericApplicationContext context;
|
162 | 165 | 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 |
166 | 166 | DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
167 | 167 | if (parent instanceof ConfigurableApplicationContext) {
|
168 | 168 | beanFactory.setBeanClassLoader(
|
169 | 169 | ((ConfigurableApplicationContext) parent).getBeanFactory().getBeanClassLoader());
|
170 | 170 | }
|
171 | 171 | else {
|
172 |
| - beanFactory.setBeanClassLoader(parent.getClassLoader()); |
| 172 | + beanFactory.setBeanClassLoader(classLoader); |
173 | 173 | }
|
174 | 174 | context = AotDetector.useGeneratedArtifacts() ? new GenericApplicationContext(beanFactory)
|
175 | 175 | : new AnnotationConfigApplicationContext(beanFactory);
|
176 |
| - context.setClassLoader(parent.getClassLoader()); |
177 | 176 | }
|
178 | 177 | else {
|
179 | 178 | context = AotDetector.useGeneratedArtifacts() ? new GenericApplicationContext()
|
180 | 179 | : new AnnotationConfigApplicationContext();
|
181 | 180 | }
|
| 181 | + context.setClassLoader(classLoader); |
182 | 182 | context.getEnvironment().getPropertySources().addFirst(
|
183 | 183 | new MapPropertySource(this.propertySourceName, Collections.singletonMap(this.propertyName, name)));
|
184 | 184 | if (this.parent != null) {
|
|
0 commit comments