首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >禁用弹簧启动执行器"health-component“和"health-component-instance”

禁用弹簧启动执行器"health-component“和"health-component-instance”
EN

Stack Overflow用户
提问于 2019-05-08 23:09:07
回答 3查看 3.1K关注 0票数 3

您好,我正在使用sprinb-boot2中的致动器,具有以下属性

代码语言:javascript
复制
management.endpoints.enabled-by-default=false
management.endpoint.health.enabled=true

我的目标是禁用除健康之外的所有端点。通过此配置,我禁用了除健康和获取以下端点以外的所有端点,现在使用"health", "health-component", "health-component-instance"。是否也可以禁用"health-component", "health-component-instance"?又是如何做到的?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2019-05-08 23:27:07

健康组件端点是作为现有HealthEndpoint的扩展在Spring Boot 2.2.0.M2中引入的。

没有仅禁用/health-component/health-component-instance的配置选项,要么禁用整个health端点,要么不禁用。

票数 4
EN

Stack Overflow用户

发布于 2019-05-09 00:06:32

对于SpringBoot 2.1.3,您可以在application.yml中使用以下内容:

代码语言:javascript
复制
#ENDPOINTS:
management:
  endpoints:
    web:
      exposure:
        include:
        - 'health'
        - 'info'

它将使执行器中仅有两个列出的端点可用。

票数 2
EN

Stack Overflow用户

发布于 2019-05-09 00:02:19

在pom.xml中添加

代码语言:javascript
复制
<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>

添加一个配置类:

代码语言:javascript
复制
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .authorizeRequests()
                .antMatchers("/actuator/health/*").authenticated()
                .antMatchers("/**").permitAll();
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56043811

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档