簡體   English   中英

新創建/擴展的 JHipster 端點不起作用(404 錯誤)

[英]Newly created / extended JHipster endpoint does not work (404 error)

我想創建一個擴展現有jhimetrics端點的新端點(或擴展現有jhimetrics的結果)。 該應用程序是使用 JHipster 生成的。 所以我所做的是:

  • 將新端點添加到application.yml文件中的數組中,特別是:
management:
    endpoints:
        web:
            base-path: /management
            exposure:
                include: [ ..., "health", "info", "jhimetrics", "roxhens"]
  • 使用以下內容創建了ExtendedMetricsEndpoint.java
// imports, etc...

@Endpoint(id = "roxhens")
public class ExtendedMetricsEndpoint {
    private final JHipsterMetricsEndpoint delegate;
    private final SimpUserRegistry simpUserRegistry;

    public ExtendedMetricsEndpoint(
        JHipsterMetricsEndpoint delegate, 
        SimpUserRegistry simpUserRegistry
    ) {
        this.delegate = delegate;
        this.simpUserRegistry = simpUserRegistry;
    }

    @ReadOperation
    public Map<String, Map> getMetrics() {
        Map<String, Map> metrics = this.delegate.allMetrics();
        HashMap<String, Integer> activeUsers = new HashMap<>();
        activeUsers.put("activeUsers", this.simpUserRegistry.getUserCount());
        metrics.put("customMetrics", new HashMap(activeUsers));
        return metrics;
    }

}
  • 為此端點創建了配置文件:
// imports etc...

@Configuration
@ConditionalOnClass(Timed.class)
@AutoConfigureAfter(JHipsterMetricsEndpointConfiguration.class)
public class ExtendedMetricsEndpointConfiguration {

    @Bean
    @ConditionalOnBean({JHipsterMetricsEndpoint.class, SimpUserRegistry.class})
    @ConditionalOnMissingBean
    @ConditionalOnAvailableEndpoint
    public ExtendedMetricsEndpoint extendedMetricsEndpoint(JHipsterMetricsEndpoint jHipsterMetricsEndpoint, SimpUserRegistry simpUserRegistry) {
        return new ExtendedMetricsEndpoint(jHipsterMetricsEndpoint, simpUserRegistry);
    }
}

我在這里錯過了什么步驟,或者我做錯了什么?

我遇到了同樣的問題,經過 2 天的努力,我找到了適合我的解決方案:

@Component
@WebEndpoint(id = "xxxmetrics")
public class XXXMetricsEndpoint {
    private final MeterRegistry meterRegistry;

    public SrnMetricsEndpoint(MeterRegistry meterRegistry) {
        this.meterRegistry = meterRegistry;
    }

    @ReadOperation
    public Map<String, Map> allMetrics() {
        Map<String, Map> stringMapMap = new LinkedHashMap<>();

        return stringMapMap;
    }
}

應用 yml:

management:
    endpoints:
        web:
            base-path: /management
            exposure:
                include: [... , 'health', 'info', 'jhimetrics', 'xxxmetrics' ,'metrics', 'logfile']

這樣請求:/management/xxxmetrics 工作。

spring 文檔: https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-features-custom

編輯:spring 版本:5.1.10,spring-boot-actuator:2.1.9

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM