Prechádzať zdrojové kódy

fix(video): 收窄MapperScan修复启动时生命周期存储歧义

Kazerin 3 týždňov pred
rodič
commit
10b3bbeb20

+ 3 - 1
video-service/src/main/java/com/zksy/video/VideoApplication.java

@@ -13,7 +13,9 @@ import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration;
 import org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration;
 
 
 @EnableScheduling
 @EnableScheduling
-@MapperScan(basePackages={"com.zksy.video","com.ruoyi.wvp.mapper"})
+// Both com.zksy.video mappers carry @Mapper themselves; a package-wide scan here would also
+// register ordinary interfaces (e.g. VideoLifecycleStore) as mappers and break injection.
+@MapperScan(basePackages={"com.ruoyi.wvp.mapper"})
 @SpringBootApplication(scanBasePackages = {"com.zksy.video", "com.ruoyi.wvp"}, exclude = {DataSourceAutoConfiguration.class,UserDetailsServiceAutoConfiguration.class})
 @SpringBootApplication(scanBasePackages = {"com.zksy.video", "com.ruoyi.wvp"}, exclude = {DataSourceAutoConfiguration.class,UserDetailsServiceAutoConfiguration.class})
 public class VideoApplication {
 public class VideoApplication {
     public static void main(String[] args) { SpringApplication.run(VideoApplication.class, args); }
     public static void main(String[] args) { SpringApplication.run(VideoApplication.class, args); }

+ 32 - 0
video-service/src/test/java/com/zksy/video/VideoApplicationWiringTest.java

@@ -0,0 +1,32 @@
+package com.zksy.video;
+
+import org.junit.jupiter.api.Test;
+import org.mybatis.spring.annotation.MapperScan;
+import java.util.Arrays;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The video module registers its two mappers with @Mapper, so a package-wide MapperScan is both
+ * unnecessary and harmful: it also turns ordinary interfaces (VideoLifecycleStore) into mapper
+ * beans, which makes VideoLifecycleService ambiguous and prevents the service from starting.
+ */
+class VideoApplicationWiringTest {
+
+    @Test
+    void mapperScanDoesNotSweepTheWholeVideoPackage() {
+        MapperScan scan = VideoApplication.class.getAnnotation(MapperScan.class);
+        assertTrue(scan != null, "VideoApplication must declare its mapper scan explicitly");
+        assertFalse(Arrays.asList(scan.basePackages()).contains("com.zksy.video"),
+                "com.zksy.video must not be scanned for mappers: it holds ordinary interfaces such as VideoLifecycleStore");
+        assertTrue(Arrays.asList(scan.basePackages()).contains("com.ruoyi.wvp.mapper"),
+                "the wvp mappers still need the package scan");
+    }
+
+    @Test
+    void bothVideoMappersDeclareThemselvesSoThePackageScanIsNotNeeded() {
+        assertTrue(RegisteredVideoMapper.class.isAnnotationPresent(org.apache.ibatis.annotations.Mapper.class));
+        assertTrue(VideoEquipmentStatusMapper.class.isAnnotationPresent(org.apache.ibatis.annotations.Mapper.class));
+    }
+}