プログラム的に春ブーツ2を使用して、すべてのアクチュエータのエンドポイントを取得するには?

ヴォイチェフWirzbicki:

春のブート1.xでは、プログラム的に、すべてのアクチュエータのエンドポイントを解決することが可能でした。私はすべてのアクチュエータのエンドポイントパスを露出豆を有します

@Component
public class MyProjectActuatorEndpoints {

    @Autowired
    private MvcEndpoints endpoints;

    public String[] getActuatorEndpointPaths() {
        return endpoints.getEndpoints().stream()
            .map(MvcEndpoint::getPath)
            .map(path -> path + "/**")
            .toArray(String[]::new);
    }
}

残念ながら、春ブーツアクチュエータ2.0.5.RELEASEにはそのようなクラスMvcEndpointsはありません。春の新バージョンでは、このクラスの任意の代替はありますか?

アンディ・ブラウン:

あなたが必要とするすべてはであるorg.springframework.boot.actuate.endpoint.web.PathMappedEndpoints豆。あなたがしゃれを許します場合、これは、正しい道にあなたを設定する必要があります。

@Slf4j
@Component
public class ActuatorLogger {

  public ActuatorLogger(@Autowired PathMappedEndpoints pme) {
    log.info("Actuator base path: {}", pme.getBasePath());
    pme.getAllPaths().forEach(p -> log.info("Path: {}", p));
  }
}

org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequestあなたは、コードからそれを行う必要があるときに、アクチュエータのエンドポイントの春のセキュリティルールを設定する助けに利用可能です。たとえば、あなたにWebSecurityConfigurerAdapter実装、このフラグメントは、既存のルールにマージすることができます。

http.authorizeRequests()
      .requestMatchers(EndpointRequest.to(ShutdownEndpoint.class))
      .hasAnyAuthority("ROLE_ADMIN", "ROLE_SUPPORT")

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=176466&siteId=1
おすすめ