Отключите исполнительные механизмы пружинной загрузки "компонент здоровья" и "экземпляр компонента здоровья" - PullRequest
3 голосов
/ 08 мая 2019

Привет! Я использую привод в sprinb-boot 2 со следующими свойствами

management.endpoints.enabled-by-default=false
management.endpoint.health.enabled=true

Моя цель - отключить все конечные точки, кроме здоровья. По этой конфигурации я отключил все кроме здоровья и теперь получаю следующие конечные точки "health", "health-component", "health-component-instance". Можно ли также отключить "health-component", "health-component-instance"? И как?

Ответы [ 3 ]

3 голосов
/ 08 мая 2019

Конечные точки компонента здоровья были введены в Spring Boot 2.2.0.M2 как расширение к уже существующим HealthEndpoint.

Нет опции конфигурации для отключения только /health-component и /health-component-instance, либо вся конечная точка health отключена, либо нет.

1 голос
/ 08 мая 2019

Для SpringBoot 2.1.3 вы можете использовать следующее в вашем application.yml:

#ENDPOINTS:
management:
  endpoints:
    web:
      exposure:
        include:
        - 'health'
        - 'info'

Это сделает только две перечисленные конечные точки доступными из привода.

1 голос
/ 08 мая 2019

добавить в pom.xml

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>

Добавить класс конфигурации:

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();
    }
}
...