English 中文(简体)
无端转化器,[G.org. mersframework.postactuate.health.SystemHealth],先令内容-Type
原标题:No converter for [class org.springframework.boot.actuate.health.SystemHealth] with preset Content-Type null

I am facing this below issue.. when i start hitting the http://localhost:8080/actuator/health url. May i know any one faced the same issue? I am unable figure out the issue.

ERROR o.a.c.c.C.[.[.[.[dispatcherServlet].log - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.http.converter.HttpMessageNotWritableException: No converter for [class org.springframework.boot.actuate.health.SystemHealth] with preset Content-Type null ] with root cause org.springframework.http.converter.HttpMessageNotWritableException: No converter for [class org.springframework.boot.actuate.health.SystemHealth] with preset Content-Type null

问题回答

当我创立一个有3.2.0波特的具体单位测试班时,我也存在同样的问题。

你可以看到一个与你相近的问题,其错误信息是:here。 该案由Jackson格式引发。

在我的案件中,问题与没有, 带来一个转换器。 如果你使用@SpringBoot 试验通知,请在您的前面注明。 单位测试班,自动产生。 但是,在我的案件中,当我决定成立一个单位测试班,重点是按照我申请时宣布的每个终点,只检查春布特人配置时,问题就消失了。 yaml. 单位测试组的目标是避免在更新或回归过程中发生意外的配置,并大张旗鼓地暴露终点。 由我创建的单位测试班是避免通过装满所有

package br.com.test.controller;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.autoconfigure.availability.AvailabilityHealthContributorAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.availability.AvailabilityProbesAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.health.HealthEndpointAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.info.InfoEndpointAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration;
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementContextAutoConfiguration;
import org.springframework.boot.actuate.health.PingHealthIndicator;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
import org.springframework.boot.availability.ApplicationAvailabilityBean;
import org.springframework.boot.test.autoconfigure.web.servlet.MockMvcAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;

/**
 * Unit test specialized on to check Spring Boot Actuator configurations at the artifact.
 * We configure to expose only some endpoints, for example, /health, if any configuration has changed, then it ll
 * check the regression.
 */
@SpringBootTest(
        classes = HealthCheckControllerTest.CustomApplicationContext.class,
        properties = {
                "management.endpoint.health.group.liveness.include=livenessState",
                "management.endpoint.health.group.readiness.include=readinessState"})
class HealthCheckControllerTest {

    @Autowired
    private WebApplicationContext context;

    private MockMvc mockMvc;

    @BeforeEach
    public void setUp() {
        this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context).build();
    }

    @Test
    void requisitaEndpointHealth_ViaGet_deveRetornar200ComServicoUP()
            throws Exception {
        this.mockMvc.perform(MockMvcRequestBuilders.get("/health"))
                .andDo(print())
                .andExpect(MockMvcResultMatchers.status().isOk())
                .andExpect(jsonPath("$.status").value("UP"));
    }

    @Test
    void requisitaEndpointHealthLiveness_ViaGet_deveRetornar200ComServicoUP()
            throws Exception {
        this.mockMvc.perform(MockMvcRequestBuilders.get("/health/liveness"))
                .andDo(print())
                .andExpect(MockMvcResultMatchers.status().isOk())
                .andExpect(jsonPath("$.status").value("UP"));
    }

    @Test
    void requisitaEndpointHealthReadiness_ViaGet_deveRetornar200ComServicoUP()
            throws Exception {
        this.mockMvc.perform(MockMvcRequestBuilders.get("/health/readiness"))
                .andDo(print())
                .andExpect(MockMvcResultMatchers.status().isOk())
                .andExpect(jsonPath("$.status").value("UP"));
    }

    /**
     * That class allows to turn available only some Spring Boot Actuator Auto-configurations.
     *
     * By default, @SpringBootApplication loads all resources unnecessarily declared as spring boot dependencies
     * (starters).
     *
     * <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/using.html#using.auto-configuration">...</a>
     *
     */
    @Configuration
    @ManagementContextConfiguration
    @Import({
            EndpointAutoConfiguration.class,
            HealthEndpointAutoConfiguration.class,
            InfoEndpointAutoConfiguration.class,
            WebEndpointAutoConfiguration.class,
            ManagementContextAutoConfiguration.class,
            HealthCheckControllerTest.class,
            AvailabilityHealthContributorAutoConfiguration.class,
            AvailabilityProbesAutoConfiguration.class,
            PingHealthIndicator.class,
            ApplicationAvailabilityBean.class,
            MockMvcAutoConfiguration.class,
            WebMvcAutoConfiguration.class // I included it manually and solved
    })
    public class CustomApplicationContext {

    }

}

我希望你解决你的问题。 感谢。





相关问题
热门标签