Git Product home page Git Product logo

spring-cloud-restartendpoint-demo's Introduction

Spring Cloud Hoxton.SR3- RestartEndpoint cannot be autowired Build Status

Since Spring Cloud Hoxton.SR3, autowiring RestartEndpoint which was working with Hoxton.SR2, no longer works.

The endpoint is enabled with the following property:

management.endpoint.restart.enabled: true

The startup fails with the following cause: NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.cloud.context.restart.RestartEndpoint' available: expected at least 1 bean which qualifies as autowire candidate.

Solution

Looks like it was a mix of breaking changes in Spring Boot (2.2.x) and Actuator:

  1. Each individual endpoint can be enabled or disabled. This controls whether or not the endpoint is created and its bean exists in the application context. To be remotely accessible an endpoint also has to be exposed via JMX or HTTP. (https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-features.html#production-ready-endpoints)
  2. By default, this feature (JMX) is not enabled and can be turned on by setting the configuration property spring.jmx.enabled to true. (https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-features.html#production-ready-jmx)
  3. As the test context framework caches context, JMX is disabled by default to prevent identical components to register on the same domain. (https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-testing-spring-boot-applications-jmx)

So.... the endpoints must also be exposed, via HTTP or JMX. Since I just want to use the RestartEndpoint programmatically, I'll go with JMX.

To make it work in production, the following properties must be set in application.yml:

spring:
  jmx.enabled: true
management:
  endpoint.restart.enabled: true

All JMX endpoints are exposed by default, but if you customized the management.endpoints.jmx.exposure.include property with a list of endpoints (the default value is *), you will need to also add restart.

This is not enough to make it also work in a Spring Boot test! To make it work in a Spring Boot test, you must annotate the test with @SpringBootTest(properties = "spring.jmx.enabled=true"), because the value in application.yml is always overridden by default with false.

What I really can't explain is why it works with Spring Boot 2.2.5.RELEASE and Spring Cloud Hoxton.SR2.

Or maybe it is an Actuator bug? After all, the documentation says "To be remotely accessible an endpoint also has to be exposed via JMX or HTTP", but I only want to access it programmatically!

spring-cloud-restartendpoint-demo's People

Contributors

brunomendola avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.