diff --git a/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/WebMvcConfiguration.java b/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/WebMvcConfiguration.java index 1fce8270b..2515f5d03 100644 --- a/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/WebMvcConfiguration.java +++ b/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/WebMvcConfiguration.java @@ -13,9 +13,11 @@ import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer; import io.micrometer.prometheus.PrometheusMeterRegistry; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.boot.actuate.trace.http.InMemoryHttpTraceRepository; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; @@ -148,6 +150,7 @@ public class WebMvcConfiguration implements WebMvcConfigurer { * 解决metrics端点不显示jvm信息的问题(zyf) */ @Bean + @ConditionalOnBean(name = "meterRegistryPostProcessor") InitializingBean forcePrometheusPostProcessor(BeanPostProcessor meterRegistryPostProcessor) { return () -> meterRegistryPostProcessor.postProcessAfterInitialization(prometheusMeterRegistry, ""); } diff --git a/jeecg-boot/jeecg-module-system/jeecg-system-start/src/test/java/org/jeecg/modules/system/test/MockControllerTest.java b/jeecg-boot/jeecg-module-system/jeecg-system-start/src/test/java/org/jeecg/modules/system/test/MockControllerTest.java new file mode 100644 index 000000000..55087b690 --- /dev/null +++ b/jeecg-boot/jeecg-module-system/jeecg-system-start/src/test/java/org/jeecg/modules/system/test/MockControllerTest.java @@ -0,0 +1,37 @@ +package org.jeecg.modules.system.test; + +import org.jeecg.config.JeecgBaseConfig; +import org.jeecg.modules.base.service.BaseCommonService; +import org.jeecg.modules.demo.mock.MockController; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.result.MockMvcResultHandlers; +import org.springframework.test.web.servlet.result.MockMvcResultMatchers; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; + +/** + * 单个controller测试 + * @date 2025/4/7 11:21 + */ +@WebMvcTest(value = MockController.class) +public class MockControllerTest { + @Autowired + private MockMvc mockMvc; + + @MockBean + private BaseCommonService baseCommonService; + @MockBean + private JeecgBaseConfig jeecgBaseConfig; + + @Test + public void testSave() throws Exception { + mockMvc.perform(get("/mock/api/json/area")) + .andDo(MockMvcResultHandlers.print()) + .andExpect(MockMvcResultMatchers.status().isOk()); + } + +}