Config.java 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package com.provectus.kafka.ui.config;
  2. import java.util.Collections;
  3. import java.util.Map;
  4. import lombok.AllArgsConstructor;
  5. import org.openapitools.jackson.nullable.JsonNullableModule;
  6. import org.springframework.beans.factory.ObjectProvider;
  7. import org.springframework.boot.autoconfigure.web.ServerProperties;
  8. import org.springframework.boot.autoconfigure.web.reactive.WebFluxProperties;
  9. import org.springframework.context.ApplicationContext;
  10. import org.springframework.context.annotation.Bean;
  11. import org.springframework.context.annotation.Configuration;
  12. import org.springframework.http.server.reactive.ContextPathCompositeHandler;
  13. import org.springframework.http.server.reactive.HttpHandler;
  14. import org.springframework.jmx.export.MBeanExporter;
  15. import org.springframework.util.StringUtils;
  16. import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
  17. @Configuration
  18. @AllArgsConstructor
  19. public class Config {
  20. private final ApplicationContext applicationContext;
  21. private final ServerProperties serverProperties;
  22. @Bean
  23. public HttpHandler httpHandler(ObjectProvider<WebFluxProperties> propsProvider) {
  24. final String basePath = serverProperties.getServlet().getContextPath();
  25. HttpHandler httpHandler = WebHttpHandlerBuilder
  26. .applicationContext(this.applicationContext).build();
  27. if (StringUtils.hasText(basePath)) {
  28. Map<String, HttpHandler> handlersMap =
  29. Collections.singletonMap(basePath, httpHandler);
  30. return new ContextPathCompositeHandler(handlersMap);
  31. }
  32. return httpHandler;
  33. }
  34. @Bean
  35. public MBeanExporter exporter() {
  36. final var exporter = new MBeanExporter();
  37. exporter.setAutodetect(true);
  38. exporter.setExcludedBeans("pool");
  39. return exporter;
  40. }
  41. @Bean
  42. // will be used by webflux json mapping
  43. public JsonNullableModule jsonNullableModule() {
  44. return new JsonNullableModule();
  45. }
  46. }