fix: Disabled mongodb-autoconfig, if mongodb is not used
authorKai Moritz <kai@juplo.de>
Fri, 23 Feb 2024 10:39:26 +0000 (11:39 +0100)
committerKai Moritz <kai@juplo.de>
Fri, 23 Feb 2024 15:38:52 +0000 (16:38 +0100)
src/main/java/de/juplo/kafka/chat/backend/ChatBackendConfiguration.java
src/main/java/de/juplo/kafka/chat/backend/storage/files/FilesStorageConfiguration.java
src/main/java/de/juplo/kafka/chat/backend/storage/nostorage/NoStorageStorageConfiguration.java
src/test/java/de/juplo/kafka/chat/backend/InMemoryWithFilesStorageIT.java
src/test/java/de/juplo/kafka/chat/backend/domain/ChatHomeServiceTest.java

index f49e385..ad944fa 100644 (file)
@@ -1,5 +1,10 @@
 package de.juplo.kafka.chat.backend;
 
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
+import org.springframework.boot.autoconfigure.data.mongo.MongoReactiveDataAutoConfiguration;
+import org.springframework.boot.autoconfigure.data.mongo.MongoReactiveRepositoriesAutoConfiguration;
+import org.springframework.boot.autoconfigure.mongo.MongoReactiveAutoConfiguration;
 import org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
@@ -16,4 +21,15 @@ public class ChatBackendConfiguration
   {
     return Clock.systemDefaultZone();
   }
+
+
+  @ConditionalOnExpression("!'${chat.backend.inmemory.storage-strategy}'.toLowerCase().equals('mongodb')")
+  @Configuration
+  @EnableAutoConfiguration(exclude = {
+      MongoReactiveDataAutoConfiguration.class,
+      MongoReactiveAutoConfiguration.class,
+      MongoReactiveRepositoriesAutoConfiguration.class })
+  public static class DisableMongoDBConfiguration
+  {
+  }
 }
index 72f8e7d..45175c9 100644 (file)
@@ -4,11 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 import de.juplo.kafka.chat.backend.ChatBackendProperties;
 import de.juplo.kafka.chat.backend.implementation.ShardingStrategy;
 import de.juplo.kafka.chat.backend.implementation.StorageStrategy;
-import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
-import org.springframework.boot.autoconfigure.data.mongo.MongoReactiveDataAutoConfiguration;
-import org.springframework.boot.autoconfigure.data.mongo.MongoReactiveRepositoriesAutoConfiguration;
-import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 
@@ -20,11 +16,6 @@ import java.nio.file.Paths;
     name = "storage-strategy",
     havingValue = "files")
 @Configuration
-@EnableAutoConfiguration(
-    exclude = {
-        MongoReactiveDataAutoConfiguration.class,
-        MongoReactiveRepositoriesAutoConfiguration.class,
-        MongoAutoConfiguration.class })
 public class FilesStorageConfiguration
 {
   @Bean
index dc2bdfc..0d50b89 100644 (file)
@@ -1,11 +1,7 @@
 package de.juplo.kafka.chat.backend.storage.nostorage;
 
 import de.juplo.kafka.chat.backend.implementation.StorageStrategy;
-import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
-import org.springframework.boot.autoconfigure.data.mongo.MongoReactiveDataAutoConfiguration;
-import org.springframework.boot.autoconfigure.data.mongo.MongoReactiveRepositoriesAutoConfiguration;
-import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 
@@ -16,11 +12,6 @@ import org.springframework.context.annotation.Configuration;
     havingValue = "none",
     matchIfMissing = true)
 @Configuration
-@EnableAutoConfiguration(
-    exclude = {
-        MongoReactiveDataAutoConfiguration.class,
-        MongoReactiveRepositoriesAutoConfiguration.class,
-        MongoAutoConfiguration.class })
 public class NoStorageStorageConfiguration
 {
   @Bean
index e4eaf3a..0d63b7e 100644 (file)
@@ -1,8 +1,13 @@
 package de.juplo.kafka.chat.backend;
 
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
 import lombok.extern.slf4j.Slf4j;
 import org.junit.jupiter.api.BeforeEach;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.TestPropertySource;
 
 import java.io.IOException;
@@ -15,6 +20,7 @@ import java.nio.file.Paths;
     "chat.backend.inmemory.sharding-strategy=none",
     "chat.backend.inmemory.storage-strategy=files",
     "chat.backend.inmemory.storage-directory=target/files" })
+@ContextConfiguration(classes = InMemoryWithFilesStorageIT.TestConfig.class)
 @Slf4j
 public class InMemoryWithFilesStorageIT extends AbstractInMemoryStorageIT
 {
@@ -47,4 +53,17 @@ public class InMemoryWithFilesStorageIT extends AbstractInMemoryStorageIT
       Files.delete(path);
     }
   }
+
+
+  static class TestConfig
+  {
+    @Bean
+    ObjectMapper objectMapper()
+    {
+      ObjectMapper objectMapper = new ObjectMapper();
+      objectMapper.registerModule(new JavaTimeModule());
+      objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
+      return objectMapper;
+    }
+  }
 }
index 858d03d..d859b14 100644 (file)
@@ -1,5 +1,7 @@
 package de.juplo.kafka.chat.backend.domain;
 
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
 import de.juplo.kafka.chat.backend.ChatBackendProperties;
 import de.juplo.kafka.chat.backend.domain.exceptions.LoadInProgressException;
 import de.juplo.kafka.chat.backend.domain.exceptions.UnknownChatroomException;
@@ -79,6 +81,14 @@ public abstract class ChatHomeServiceTest
 
   static class TestConfiguration
   {
+    @Bean
+    ObjectMapper objectMapper()
+    {
+      ObjectMapper objectMapper = new ObjectMapper();
+      objectMapper.registerModule(new JavaTimeModule());
+      return objectMapper;
+    }
+
     @Bean
     Clock clock()
     {