@@ -71,12 +71,11 @@ class OnAvailableEndpointCondition extends SpringBootCondition {
71
71
72
72
@ Override
73
73
public ConditionOutcome getMatchOutcome (ConditionContext context , AnnotatedTypeMetadata metadata ) {
74
- Environment environment = context .getEnvironment ();
75
74
MergedAnnotation <ConditionalOnAvailableEndpoint > conditionAnnotation = metadata .getAnnotations ()
76
75
.get (ConditionalOnAvailableEndpoint .class );
77
76
Class <?> target = getTarget (context , metadata , conditionAnnotation );
78
77
MergedAnnotation <Endpoint > endpointAnnotation = getEndpointAnnotation (target );
79
- return getMatchOutcome (environment , conditionAnnotation , endpointAnnotation );
78
+ return getMatchOutcome (context , conditionAnnotation , endpointAnnotation );
80
79
}
81
80
82
81
private Class <?> getTarget (ConditionContext context , AnnotatedTypeMetadata metadata ,
@@ -109,16 +108,17 @@ protected MergedAnnotation<Endpoint> getEndpointAnnotation(Class<?> target) {
109
108
return getEndpointAnnotation (extension .getClass ("endpoint" ));
110
109
}
111
110
112
- private ConditionOutcome getMatchOutcome (Environment environment ,
111
+ private ConditionOutcome getMatchOutcome (ConditionContext context ,
113
112
MergedAnnotation <ConditionalOnAvailableEndpoint > conditionAnnotation ,
114
113
MergedAnnotation <Endpoint > endpointAnnotation ) {
115
114
ConditionMessage .Builder message = ConditionMessage .forCondition (ConditionalOnAvailableEndpoint .class );
115
+ Environment environment = context .getEnvironment ();
116
116
EndpointId endpointId = EndpointId .of (environment , endpointAnnotation .getString ("id" ));
117
117
ConditionOutcome accessOutcome = getAccessOutcome (environment , endpointAnnotation , endpointId , message );
118
118
if (!accessOutcome .isMatch ()) {
119
119
return accessOutcome ;
120
120
}
121
- ConditionOutcome exposureOutcome = getExposureOutcome (environment , conditionAnnotation , endpointAnnotation ,
121
+ ConditionOutcome exposureOutcome = getExposureOutcome (context , conditionAnnotation , endpointAnnotation ,
122
122
endpointId , message );
123
123
return (exposureOutcome != null ) ? exposureOutcome : ConditionOutcome .noMatch (message .because ("not exposed" ));
124
124
}
@@ -137,11 +137,11 @@ private Access getAccess(Environment environment, EndpointId endpointId, Access
137
137
.accessFor (endpointId , defaultAccess );
138
138
}
139
139
140
- private ConditionOutcome getExposureOutcome (Environment environment ,
140
+ private ConditionOutcome getExposureOutcome (ConditionContext context ,
141
141
MergedAnnotation <ConditionalOnAvailableEndpoint > conditionAnnotation ,
142
142
MergedAnnotation <Endpoint > endpointAnnotation , EndpointId endpointId , Builder message ) {
143
143
Set <EndpointExposure > exposures = getExposures (conditionAnnotation );
144
- Set <EndpointExposureOutcomeContributor > outcomeContributors = getExposureOutcomeContributors (environment );
144
+ Set <EndpointExposureOutcomeContributor > outcomeContributors = getExposureOutcomeContributors (context );
145
145
for (EndpointExposureOutcomeContributor outcomeContributor : outcomeContributors ) {
146
146
ConditionOutcome outcome = outcomeContributor .getExposureOutcome (endpointId , exposures , message );
147
147
if (outcome != null && outcome .isMatch ()) {
@@ -166,23 +166,25 @@ private Set<EndpointExposure> replaceCloudFoundryExposure(Collection<EndpointExp
166
166
return result ;
167
167
}
168
168
169
- private Set <EndpointExposureOutcomeContributor > getExposureOutcomeContributors (Environment environment ) {
169
+ private Set <EndpointExposureOutcomeContributor > getExposureOutcomeContributors (ConditionContext context ) {
170
+ Environment environment = context .getEnvironment ();
170
171
Set <EndpointExposureOutcomeContributor > contributors = exposureOutcomeContributorsCache .get (environment );
171
172
if (contributors == null ) {
172
173
contributors = new LinkedHashSet <>();
173
174
contributors .add (new StandardExposureOutcomeContributor (environment , EndpointExposure .WEB ));
174
175
if (environment .getProperty (JMX_ENABLED_KEY , Boolean .class , false )) {
175
176
contributors .add (new StandardExposureOutcomeContributor (environment , EndpointExposure .JMX ));
176
177
}
177
- contributors .addAll (loadExposureOutcomeContributors (environment ));
178
+ contributors .addAll (loadExposureOutcomeContributors (context . getClassLoader (), environment ));
178
179
exposureOutcomeContributorsCache .put (environment , contributors );
179
180
}
180
181
return contributors ;
181
182
}
182
183
183
- private List <EndpointExposureOutcomeContributor > loadExposureOutcomeContributors (Environment environment ) {
184
+ private List <EndpointExposureOutcomeContributor > loadExposureOutcomeContributors (ClassLoader classLoader ,
185
+ Environment environment ) {
184
186
ArgumentResolver argumentResolver = ArgumentResolver .of (Environment .class , environment );
185
- return SpringFactoriesLoader .forDefaultResourceLocation ()
187
+ return SpringFactoriesLoader .forDefaultResourceLocation (classLoader )
186
188
.load (EndpointExposureOutcomeContributor .class , argumentResolver );
187
189
}
188
190
0 commit comments