“专用的Spring Boot Actuator URL”

huangapple go评论66阅读模式
英文:

Dedicated spring boot actuator URL

问题

Here is the translated content:

Context :

Spring Boot 2.7.4

Configuration tried (beyond several) :

management:
  server:
    port: 8080
  endpoints:
    web:
      base-path: "/monitoring"
      exposure:
        include: "*"
server:
  port: 8080
  servlet:
    context-path: /myapp

What I try to get :

获取两个不同的URL:

http://localhost:8080/myapp
返回 "hello world"

http://localhost:8080/monitoring
返回 actuator

What I get :

HTTP错误 401

我尝试了许多不同的配置,但我想知道我漏掉了什么。你知道问题在哪里吗?

英文:

Context :

Spring boot 2.7.4

Configuration tried (beyond several) :

management:
  server:
    port: 8080
  endpoints:
    web:
      base-path: "/monitoring"
      exposure:
        include: "*"
server:
  port: 8080
  servlet:
    context-path: /myapp

What I try to get :

get two different URL :

http://localhost:8080/myapp
returns "hello world"

http://localhost:8080/monitoring
returns actuator

What I get :

HTTP ERROR 401

I've tried so many different configurations, but I wonder what I missed. Do you know where is the problem ?

答案1

得分: 1

Actuator是应用程序的一部分,因此它位于与您在Spring应用程序之外定义的上下文相同的上下文中,现在可以在您的http://localhost:8080/myapp/monitoring上运行。

要实现您想要的效果,您可以在控制器类中使用@RequestMapping("myapp"),这样您的路径将会有前缀,并且可以将context-path保留为/(或从配置中省略它);

英文:

Actuator is part of the application, therfore it is in the same context which you define beyond spring app - servlet - and this now works for your http://localhost:8080/myapp/monitoring

To do what you want, you can for example, in controller classes you can use @RequestMapping("myapp") to have your paths prefixed and leave context-path as / (or ommit it from your configuration);

huangapple
  • 本文由 发表于 2023年5月11日 17:39:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76226217.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定