Skip to content

Commit

Permalink
An unresolvable circular reference with management.endpoint.gateway.e…
Browse files Browse the repository at this point in the history
…nabled=true. Fixes springdoc#2814
  • Loading branch information
bnasslahsen committed Dec 29, 2024
1 parent 896471f commit 1461070
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@
import org.springdoc.core.properties.SpringDocConfigProperties;
import org.springdoc.core.utils.Constants;

import org.springframework.beans.BeansException;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.web.context.WebServerApplicationContext;
import org.springframework.boot.web.context.WebServerInitializedEvent;
import org.springframework.boot.web.server.WebServer;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationListener;
import org.springframework.util.AntPathMatcher;
import org.springframework.web.method.HandlerMethod;
Expand All @@ -54,7 +56,7 @@
*
* @author bnasslahsen
*/
public abstract class ActuatorProvider implements ApplicationListener<WebServerInitializedEvent> {
public abstract class ActuatorProvider implements ApplicationListener<WebServerInitializedEvent>, ApplicationContextAware {

/**
* The Management server properties.
Expand Down Expand Up @@ -91,6 +93,11 @@ public abstract class ActuatorProvider implements ApplicationListener<WebServerI
*/
protected ApplicationContext managementApplicationContext;

/**
* The Application context.
*/
protected ApplicationContext applicationContext;

/**
* Instantiates a new Actuator provider.
*
Expand Down Expand Up @@ -213,4 +220,8 @@ public int getActuatorPort() {
*/
public abstract Map getMethods();

@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import org.springframework.boot.actuate.autoconfigure.web.server.ConditionalOnManagementPort;
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementPortType;
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties;
import org.springframework.boot.actuate.endpoint.web.reactive.ControllerEndpointHandlerMapping;
import org.springframework.boot.actuate.endpoint.web.reactive.WebFluxEndpointHandlerMapping;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
Expand Down Expand Up @@ -167,8 +166,6 @@ static class SpringDocWebFluxActuatorConfiguration {
* @param springDocConfigProperties the spring doc config properties
* @param managementServerProperties the management server properties
* @param webEndpointProperties the web endpoint properties
* @param webFluxEndpointHandlerMapping the web flux endpoint handler mapping
* @param controllerEndpointHandlerMapping the controller endpoint handler mapping
* @return the actuator provider
*/
@Bean
Expand All @@ -178,15 +175,11 @@ static class SpringDocWebFluxActuatorConfiguration {
ActuatorProvider actuatorProvider(ServerProperties serverProperties,
SpringDocConfigProperties springDocConfigProperties,
Optional<ManagementServerProperties> managementServerProperties,
Optional<WebEndpointProperties> webEndpointProperties,
Optional<WebFluxEndpointHandlerMapping> webFluxEndpointHandlerMapping,
Optional<ControllerEndpointHandlerMapping> controllerEndpointHandlerMapping) {
Optional<WebEndpointProperties> webEndpointProperties) {
return new ActuatorWebFluxProvider(serverProperties,
springDocConfigProperties,
managementServerProperties,
webEndpointProperties,
webFluxEndpointHandlerMapping,
controllerEndpointHandlerMapping);
webEndpointProperties);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.springframework.boot.actuate.endpoint.web.reactive.ControllerEndpointHandlerMapping;
import org.springframework.boot.actuate.endpoint.web.reactive.WebFluxEndpointHandlerMapping;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.context.ApplicationContextAware;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.reactive.result.method.RequestMappingInfo;

Expand All @@ -47,46 +48,33 @@
*
* @author bnasslahsen
*/
public class ActuatorWebFluxProvider extends ActuatorProvider {

/**
* The Web flux endpoint handler mapping.
*/
private WebFluxEndpointHandlerMapping webFluxEndpointHandlerMapping;

/**
* The Controller endpoint handler mapping.
*/
private ControllerEndpointHandlerMapping controllerEndpointHandlerMapping;
public class ActuatorWebFluxProvider extends ActuatorProvider implements ApplicationContextAware {


/**
* Instantiates a new Actuator web flux provider.
*
* @param serverProperties the server properties
* @param springDocConfigProperties the spring doc config properties
* @param managementServerProperties the management server properties
* @param webEndpointProperties the web endpoint properties
* @param webFluxEndpointHandlerMapping the web flux endpoint handler mapping
* @param controllerEndpointHandlerMapping the controller endpoint handler mapping
*/
public ActuatorWebFluxProvider(ServerProperties serverProperties,
SpringDocConfigProperties springDocConfigProperties,
Optional<ManagementServerProperties> managementServerProperties,
Optional<WebEndpointProperties> webEndpointProperties,
Optional<WebFluxEndpointHandlerMapping> webFluxEndpointHandlerMapping,
Optional<ControllerEndpointHandlerMapping> controllerEndpointHandlerMapping) {
Optional<WebEndpointProperties> webEndpointProperties) {
super(managementServerProperties, webEndpointProperties, serverProperties, springDocConfigProperties);
webFluxEndpointHandlerMapping.ifPresent(webFluxEndpointHandlerMapping1 -> this.webFluxEndpointHandlerMapping = webFluxEndpointHandlerMapping1);
controllerEndpointHandlerMapping.ifPresent(controllerEndpointHandlerMapping1 -> this.controllerEndpointHandlerMapping = controllerEndpointHandlerMapping1);
}

public Map<RequestMappingInfo, HandlerMethod> getMethods() {
Map<RequestMappingInfo, HandlerMethod> mappingInfoHandlerMethodMap = new HashMap<>();

WebFluxEndpointHandlerMapping webFluxEndpointHandlerMapping = applicationContext.getBeansOfType(WebFluxEndpointHandlerMapping.class).values().stream().findFirst().orElse(null);
if (webFluxEndpointHandlerMapping == null)
webFluxEndpointHandlerMapping = managementApplicationContext.getBean(WebFluxEndpointHandlerMapping.class);
mappingInfoHandlerMethodMap.putAll(webFluxEndpointHandlerMapping.getHandlerMethods());

ControllerEndpointHandlerMapping controllerEndpointHandlerMapping = applicationContext.getBeansOfType(ControllerEndpointHandlerMapping.class).values().stream().findFirst().orElse(null);
if (controllerEndpointHandlerMapping == null)
controllerEndpointHandlerMapping = managementApplicationContext.getBean(ControllerEndpointHandlerMapping.class);
mappingInfoHandlerMethodMap.putAll(controllerEndpointHandlerMapping.getHandlerMethods());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
import org.springframework.boot.actuate.autoconfigure.web.server.ConditionalOnManagementPort;
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementPortType;
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties;
import org.springframework.boot.actuate.endpoint.web.servlet.ControllerEndpointHandlerMapping;
import org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
Expand Down Expand Up @@ -198,8 +197,6 @@ static class SpringDocWebMvcActuatorConfiguration {
* @param springDocConfigProperties the spring doc config properties
* @param managementServerProperties the management server properties
* @param webEndpointProperties the web endpoint properties
* @param webMvcEndpointHandlerMapping the web mvc endpoint handler mapping
* @param controllerEndpointHandlerMapping the controller endpoint handler mapping
* @return the actuator provider
*/
@Bean
Expand All @@ -209,15 +206,11 @@ static class SpringDocWebMvcActuatorConfiguration {
ActuatorProvider actuatorProvider(ServerProperties serverProperties,
SpringDocConfigProperties springDocConfigProperties,
Optional<ManagementServerProperties> managementServerProperties,
Optional<WebEndpointProperties> webEndpointProperties,
Optional<WebMvcEndpointHandlerMapping> webMvcEndpointHandlerMapping,
Optional<ControllerEndpointHandlerMapping> controllerEndpointHandlerMapping) {
Optional<WebEndpointProperties> webEndpointProperties) {
return new ActuatorWebMvcProvider(serverProperties,
springDocConfigProperties,
managementServerProperties,
webEndpointProperties,
webMvcEndpointHandlerMapping,
controllerEndpointHandlerMapping);
webEndpointProperties);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,45 +51,31 @@
*/
public class ActuatorWebMvcProvider extends ActuatorProvider {

/**
* The Web mvc endpoint handler mapping.
*/
private WebMvcEndpointHandlerMapping webMvcEndpointHandlerMapping;

/**
* The Controller endpoint handler mapping.
*/
private ControllerEndpointHandlerMapping controllerEndpointHandlerMapping;

/**
* Instantiates a new Actuator web mvc provider.
*
* @param serverProperties the server properties
* @param springDocConfigProperties the spring doc config properties
* @param managementServerProperties the management server properties
* @param webEndpointProperties the web endpoint properties
* @param webMvcEndpointHandlerMapping the web mvc endpoint handler mapping
* @param controllerEndpointHandlerMapping the controller endpoint handler mapping
* @param serverProperties the server properties
* @param springDocConfigProperties the spring doc config properties
* @param managementServerProperties the management server properties
* @param webEndpointProperties the web endpoint properties
*/
public ActuatorWebMvcProvider(ServerProperties serverProperties,
SpringDocConfigProperties springDocConfigProperties,
Optional<ManagementServerProperties> managementServerProperties,
Optional<WebEndpointProperties> webEndpointProperties,
Optional<WebMvcEndpointHandlerMapping> webMvcEndpointHandlerMapping,
Optional<ControllerEndpointHandlerMapping> controllerEndpointHandlerMapping) {
Optional<WebEndpointProperties> webEndpointProperties) {
super(managementServerProperties, webEndpointProperties, serverProperties, springDocConfigProperties);
webMvcEndpointHandlerMapping.ifPresent(webMvcEndpointHandlerMapping1 -> this.webMvcEndpointHandlerMapping = webMvcEndpointHandlerMapping1);
controllerEndpointHandlerMapping.ifPresent(controllerEndpointHandlerMapping1 -> this.controllerEndpointHandlerMapping = controllerEndpointHandlerMapping1);
}

@Override
public Map<RequestMappingInfo, HandlerMethod> getMethods() {
Map<RequestMappingInfo, HandlerMethod> mappingInfoHandlerMethodMap = new HashMap<>();

WebMvcEndpointHandlerMapping webMvcEndpointHandlerMapping = applicationContext.getBeansOfType(WebMvcEndpointHandlerMapping.class).values().stream().findFirst().orElse(null);
if (webMvcEndpointHandlerMapping == null)
webMvcEndpointHandlerMapping = managementApplicationContext.getBean(WebMvcEndpointHandlerMapping.class);
mappingInfoHandlerMethodMap.putAll(webMvcEndpointHandlerMapping.getHandlerMethods());

ControllerEndpointHandlerMapping controllerEndpointHandlerMapping = applicationContext.getBeansOfType(ControllerEndpointHandlerMapping.class).values().stream().findFirst().orElse(null);
if (controllerEndpointHandlerMapping == null)
controllerEndpointHandlerMapping = managementApplicationContext.getBean(ControllerEndpointHandlerMapping.class);
mappingInfoHandlerMethodMap.putAll(controllerEndpointHandlerMapping.getHandlerMethods());
Expand All @@ -102,4 +88,4 @@ public String getContextPath() {
return StringUtils.defaultIfEmpty(serverProperties.getServlet().getContextPath(), EMPTY);
}

}
}

0 comments on commit 1461070

Please sign in to comment.