1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.bremersee.geojson.spring.boot.autoconfigure.web;
18
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21 import org.bremersee.geojson.GeoJsonGeometryFactory;
22 import org.bremersee.geojson.converter.GeometryConverters;
23 import org.bremersee.geojson.spring.boot.autoconfigure.GeoJsonGeometryFactoryAutoConfiguration;
24 import org.jspecify.annotations.NonNull;
25 import org.springframework.beans.factory.ObjectProvider;
26 import org.springframework.boot.autoconfigure.AutoConfiguration;
27 import org.springframework.boot.autoconfigure.AutoConfigureAfter;
28 import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
29 import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
30 import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
31 import org.springframework.boot.context.event.ApplicationReadyEvent;
32 import org.springframework.context.event.EventListener;
33 import org.springframework.format.FormatterRegistry;
34 import org.springframework.util.ClassUtils;
35 import org.springframework.web.reactive.config.WebFluxConfigurer;
36
37
38
39
40
41
42 @ConditionalOnClass(name = {"org.bremersee.geojson.converter.GeometryConverters"})
43 @ConditionalOnWebApplication(type = Type.REACTIVE)
44 @AutoConfiguration
45 @AutoConfigureAfter(GeoJsonGeometryFactoryAutoConfiguration.class)
46 public class GeoJsonWebFluxConfigurer implements WebFluxConfigurer {
47
48 private static final Log log = LogFactory.getLog(GeoJsonWebFluxConfigurer.class);
49
50 private final GeoJsonGeometryFactory geometryFactory;
51
52
53
54
55
56
57 public GeoJsonWebFluxConfigurer(ObjectProvider<GeoJsonGeometryFactory> geometryFactory) {
58 this.geometryFactory = geometryFactory.getIfAvailable(GeoJsonGeometryFactory::new);
59 }
60
61
62
63
64 @EventListener(ApplicationReadyEvent.class)
65 public void init() {
66 log.info(String.format("""
67
68 *********************************************************************************
69 * %s
70 *********************************************************************************""",
71 ClassUtils.getUserClass(getClass()).getSimpleName()));
72 }
73
74 @Override
75 public void addFormatters(@NonNull FormatterRegistry registry) {
76 GeometryConverters.getConvertersToRegister(geometryFactory)
77 .forEach(registry::addConverter);
78 }
79
80 }