"Cannot resolve configuration property" in Spring boot when trying to configure probes - spring-boot

In my Spring Boot 2.3.3.RELEASE I'm tyring to enable to readiness and liveness endpoints.
I added this to the yml file:
But IntelliJ marks the values with "Cannot resolve configuration property" , and the endpoints are not accessible (e.g. http://localhost:8080/actuator/health/readiness)

The project was missing the trivial dependency of the actuator:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
After adding it, the IntelliJ stopped complaining and the endpoints are accessible.

Related

How to externalize spring.cloud.vault.* properties to a spring cloud config server

I am using spring boot 2.7.8
I am following this https://docs.spring.io/spring-cloud-vault/docs/current/reference/html/#client-side-usage and https://docs.spring.io/spring-cloud-config/docs/current/reference/html/#_client_side_usage
I have a spring cloud config server too which hosts the externalized properties for my application. So my pom.xml has below
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-vault-config</artifactId>
</dependency>
I can point to the external spring cloud config server using the below in my properties file
spring.config.import=optional:configserver:http://myconfigserver.com
But as per https://docs.spring.io/spring-cloud-vault/docs/current/reference/html/#client-side-usage, I still have to define spring.cloud.vault.* in my application properties? How can I move spring.cloud.vault.* properties into my spring cloud config server so that all my properties are externalized. I want to avoid having some properties within the application and some externalized.
Please help to clarify if I am misunderstanding this

Azure AppConfiguration with Spring Boot 2.5.x

Question
How to integrate an Azure AppConfiguration with SpringBoot 2.5.x or higher?
Info
Im trying to use an Azure AppConfiguration resource with a Spring Boot 2.5.4 project. Unfortunately I cant get it to read a setting from the AppConfiguration or even connect to it as far as I can tell.
The project is newly created with the Spring Initializr where I only added
Spring Boot Starter Web
Spring Boot Starter Security
Spring Boot Starter WebSocket
Afterwards I tried following the Microsoft Quickstart documentation with no success. The documentation mentions that its using Spring 2.4.x so I assume some changes broke it.
I also tried to identify the issue by looking through some Azure Spring Boot Code Samples.
All the examples so far use the bootstrap.properties file which I learned during my search so far is deprecated. Moving the settings to the application.yml or enabling use-legacy-processing: true did not work either. Any ideas?
pom.xml
...
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
...
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>com.azure.spring</groupId>
<artifactId>azure-spring-cloud-appconfiguration-config</artifactId>
<version>2.0.0</version>
</dependency>
...
application.yml
spring:
config:
use-legacy-processing: true
profiles:
active: "develop"
application:
name: "MySampleService"
cloud:
azure:
appconfiguration:
stores:
- connection-string: "SomeAzureAppConfigurationResourceConnectionString"
label: ${spring.profiles.active}
#mysampleservice:
# message: "this is a message from file"
AppConfiguration Resource
Im not entirely sure about the format for the setting name. I tried to build the format based on this documentation.
The configuration classes should be fine since commenting in the mysampleservice causes the value of message beeing used.
Any hints are appreciated!
Some more info to elaborate on the accepted answer
The documentation linked in the answer refers to two different packages. The one linked right at the start in the maven repository is spring-cloud-azure-appconfiguration-config while the one used further down is azure-spring-cloud-appconfiguration-config. The second one works with the bootstrap.properties file.
Working pom.xml and bootstrap.properties:
...
<dependencies>
<!-- Dependency to load configuration from azure app configuration resource. Note that additional settings are required in bootstrap.properties
Documentation of settings: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/appconfiguration/azure-spring-cloud-starter-appconfiguration-config
-->
<dependency>
<groupId>com.azure.spring</groupId>
<artifactId>azure-spring-cloud-appconfiguration-config-web</artifactId>
<version>2.1.0</version>
</dependency>
...
# Use this to enable or disable the cloud config, disabling it results in application.yaml beeing used.
spring.cloud.azure.appconfiguration.enabled=true
# Connection string to azure app configuration resource
spring.cloud.azure.appconfiguration.stores[0].connection-string= Endpoint=https://myofficeconfiguration.azconfig.io;Id=zUcT-l9-s0:PFYfW7WM0/Pz7WZOnH3v;Secret=JTB9myJqGekDAJ5m8Z1vjmkJZrPd88JbOEE3EqoqJYs=
# Configured filters for settings in the previous defined app configuration resource
spring.cloud.azure.appconfiguration.stores[0].selects[0].key-filter = /mysampleservice/
spring.cloud.azure.appconfiguration.stores[0].selects[0].label-filter = Sample
spring.cloud.azure.appconfiguration.stores[0].selects[1].key-filter = /notificationservice/
spring.cloud.azure.appconfiguration.stores[0].selects[1].label-filter = Sample2
bootstrap.yml/bootstrap.properties can still be used, they are no longer part of the base Spring packages.
Also, you want to use this doc for 2.0.0 and newer https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/appconfiguration/azure-spring-cloud-starter-appconfiguration-config.

Spring boot 2 actuator without autoconfiguration

Can anyone help me to figure out how to enable actuator endpoints without using autoconfiguration dependencies?
I'm working on a Spring-Boot 2 project but starter poms and autocnfiguration dependencies are forbidden.
Try to adding this dependency :
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
<version>2.1.0.RELEASE</version>
</dependency>
And add this on application.properties in order to enable all endpoints of actuator if you want enable all.
management.endpoints.web.exposure.include=*

Cannot include Prometheus metrics in spring boot 2 (version 2.0.0.M7)

Cannot include Prometheus metrics in spring boot 2 (version 2.0.0.M7) project.
According micrometer docs added spring-boot-starter-actuator dependency and in application.yaml added management.endpoints.web.expose: prometheus but when calling /actuator/prometheus get
{
"timestamp": 1518159066052,
"path": "/actuator/prometheus",
"message": "Response status 404 with reason \"No matching handler\"",
"status": 404,
"error": "Not Found"
}
Tell me please why I wasn't getting prometheus metrics?
I had trouble initiating micrometer with Springboot 2. x.
These changes in my project helped me to expose the metrics atactuator/prometheus endpoint
These are the changes in my application.properties file
management.endpoints.web.exposure.include=*
management.endpoint.metrics.enabled=true
My build.gradle file included
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('io.micrometer:micrometer-registry-prometheus')
Edit: Since I gave this answer a lot has changed. It was valid for 2.0.0.RC1. Please read the documentation https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-metrics.html
If above solution doesn't work for someone try this:
I had the same issue with Spring Boot 2.0.0.RC1, spring-boot-starter-web and of course spring-boot-starter-actuator.
My application.properties file read:
management.endpoints.web.expose=prometheus,metrics,info,health
In my pom file I had additionally:
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient</artifactId>
<version>0.2.0</version>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>0.12.0.RELEASE</version>
</dependency>
Prometheus metrics under /actuator/prometheus where only shown after I had switched to the newest version of micrometer-registry-prometheus:
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>1.0.0-rc.9</version>
</dependency>
Did you add micrometer-registry-prometheus to your dependecies?
Micrometer has a pluggable architecture where you need to define (by plugging dependencies) what monitoring system you'd like to work with. (You can even add multiple, not just one.)
Btw, you should be switching to Spring Boot 2.0.0.RC1. That's the current one as of this writing.
Recap:
pom.xml
<parent>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.5</version>
</parent>
... ... ...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
application.properties.yml (aka. application.yml)
management.endpoints.web.exposure.include=health,info,prometheus
management.endpoint.metrics.enabled=true
management.endpoint.prometheus.enabled=true
management.endpoint.health.show-details=always
management.endpoint.health.show-components=always
management.endpoint.health.probes.enabled=true
management.metrics.tags.application=TheApplicationName
After applying all the above, health & info endpoints were displayed in the http://localhost:8080/actuator -list, but not the prometheus endpoint.
Of course, rerun the Maven lifecycle - still failing prometheus to be displayed ...
Finally my issue disappeared after invalidate caches and restart of my IntelliJ IDE

Spring boot actuator "/health" is not working

I have a running Springboot application which serves the URL http://localhost:8081/topics and returns me JSON response as expected.
I added actuator dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<scope>test</scope>
</dependency>
as suggested in tutorial
But when I hit http://localhost:8081/health it does not give expected result. It says
{
"timestamp": 1497952368055,
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/health"
}
Spring boot version is 1.5.4.RELEASE. And Java 1.8
What additional settings do I need to do ?
In Spring Boot 2.0.0 you have to use /actuator/health
and in the application.properties file add the following line:
management.endpoint.health.show-details=always
Do the following steps : -
Change the scope of actuator dependency from test to compile
Instead of using /health use /actuator/health
If you want to see details of the health status then addmanagement.endpoint.health.show-details=always in the application.properties file.
In your dependency you have declared
<scope>test</scope>
It means that
test
This scope indicates that the dependency is not required for normal
use of the application, and is only available for the test compilation
and execution phases.
If you want it available for normal use of the application remove <scope>test</scope> or change it to <scope>compile</scope>
Add Maven dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Application.properties
management.endpoints.web.exposure.include= "*" include all endpoints on actuator
or
management.endpoints.web.exposure.include= health if need only health endpoint
Maven dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Application.properties
spring.profiles.active=local
server.port = 9292
management.endpoints.web.exposure.include=env,health,metrics
For reference use below link:(step by step explanation)
https://www.youtube.com/watch?v=0Dj2tsK2V2g

Resources