File tree Expand file tree Collapse file tree 5 files changed +38
-6
lines changed
sdk/core/azure-core/src/main/java/com/azure/core Expand file tree Collapse file tree 5 files changed +38
-6
lines changed Original file line number Diff line number Diff line change @@ -17,8 +17,15 @@ public final class HttpPolicyProviders {
1717 private static final List <AfterRetryPolicyProvider > AFTER_PROVIDER = new ArrayList <>();
1818
1919 static {
20- ServiceLoader .load (BeforeRetryPolicyProvider .class ).forEach (BEFORE_PROVIDER ::add );
21- ServiceLoader .load (AfterRetryPolicyProvider .class ).forEach (AFTER_PROVIDER ::add );
20+ // Use as classloader to load provider-configuration files and provider classes the classloader
21+ // that loaded this class. In most cases this will be the System classloader.
22+ // But this choice here provides additional flexibility in managed environments that control
23+ // classloading differently (OSGi, Spring and others) and don't/ depend on the
24+ // System classloader to load BeforeRetryPolicyProvider and AfterRetryPolicyProvider classes.
25+ ServiceLoader .load (BeforeRetryPolicyProvider .class , HttpPolicyProviders .class .getClassLoader ())
26+ .forEach (BEFORE_PROVIDER ::add );
27+ ServiceLoader .load (AfterRetryPolicyProvider .class , HttpPolicyProviders .class .getClassLoader ())
28+ .forEach (AFTER_PROVIDER ::add );
2229 }
2330
2431 private HttpPolicyProviders () {
Original file line number Diff line number Diff line change @@ -23,7 +23,14 @@ public final class HttpClientProviders {
2323 private static HttpClientProvider defaultProvider ;
2424
2525 static {
26- ServiceLoader <HttpClientProvider > serviceLoader = ServiceLoader .load (HttpClientProvider .class );
26+ // Use as classloader to load provider-configuration files and provider classes the classloader
27+ // that loaded this class. In most cases this will be the System classloader.
28+ // But this choice here provides additional flexibility in managed environments that control
29+ // classloading differently (OSGi, Spring and others) and don't/ depend on the
30+ // System classloader to load HttpClientProvider classes.
31+ ServiceLoader <HttpClientProvider > serviceLoader = ServiceLoader .load (
32+ HttpClientProvider .class ,
33+ HttpClientProviders .class .getClassLoader ());
2734 // Use the first provider found in the service loader iterator.
2835 Iterator <HttpClientProvider > it = serviceLoader .iterator ();
2936 if (it .hasNext ()) {
Original file line number Diff line number Diff line change @@ -65,7 +65,14 @@ private static synchronized void loadDefaultSerializer() {
6565 }
6666
6767 attemptedLoad = true ;
68- Iterator <JsonSerializerProvider > iterator = ServiceLoader .load (JsonSerializerProvider .class ).iterator ();
68+ // Use as classloader to load provider-configuration files and provider classes the classloader
69+ // that loaded this class. In most cases this will be the System classloader.
70+ // But this choice here provides additional flexibility in managed environments that control
71+ // classloading differently (OSGi, Spring and others) and don't/ depend on the
72+ // System classloader to load JsonSerializerProviders classes.
73+ Iterator <JsonSerializerProvider > iterator =
74+ ServiceLoader .load (JsonSerializerProvider .class , JsonSerializerProviders .class .getClassLoader ())
75+ .iterator ();
6976 if (iterator .hasNext ()) {
7077 jsonSerializerProvider = iterator .next ();
7178 }
Original file line number Diff line number Diff line change @@ -38,8 +38,14 @@ private static synchronized void loadFromClasspath() {
3838 }
3939
4040 attemptedLoad = true ;
41+ // Use as classloader to load provider-configuration files and provider classes the classloader
42+ // that loaded this class. In most cases this will be the System classloader.
43+ // But this choice here provides additional flexibility in managed environments that control
44+ // classloading differently (OSGi, Spring and others) and don't/ depend on the
45+ // System classloader to load MemberNameConverterProviders classes.
4146 Iterator <MemberNameConverterProvider > iterator =
42- ServiceLoader .load (MemberNameConverterProvider .class ).iterator ();
47+ ServiceLoader .load (MemberNameConverterProvider .class , MemberNameConverterProviders .class .getClassLoader ())
48+ .iterator ();
4349 if (iterator .hasNext ()) {
4450 defaultProvider = iterator .next ();
4551 } else {
Original file line number Diff line number Diff line change @@ -18,7 +18,12 @@ public final class TracerProxy {
1818 private static Tracer tracer ;
1919
2020 static {
21- ServiceLoader <Tracer > serviceLoader = ServiceLoader .load (Tracer .class );
21+ // Use as classloader to load provider-configuration files and provider classes the classloader
22+ // that loaded this class. In most cases this will be the System classloader.
23+ // But this choice here provides additional flexibility in managed environments that control
24+ // classloading differently (OSGi, Spring and others) and don't/ depend on the
25+ // System classloader to load Tracer classes.
26+ ServiceLoader <Tracer > serviceLoader = ServiceLoader .load (Tracer .class , TracerProxy .class .getClassLoader ());
2227 Iterator <?> iterator = serviceLoader .iterator ();
2328 if (iterator .hasNext ()) {
2429 tracer = serviceLoader .iterator ().next ();
You can’t perform that action at this time.
0 commit comments