Unable to access /actuator endpoints - spring

I've got a small project running Spring Boot and Spring Cloud Streams with version Greenwich.SR4.
So far I've tried to include the following dependency.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator-autoconfigure</artifactId>
</dependency>
Wanting to have a /check/health endpoint which basically returns a code 200.
I've modified the config accordingly so that I don't have useless health configs within.
management.endpoints.web.base-path=/check
management.endpoint.health.enabled=true
management.health.solr.enabled=false
management.health.elasticsearch.enabled=false
However, whenever I try to run localhost:8080/check/health a 404 is prompted. What could be happening?
Also mentioning that I've tried including my own #RestController but same behavior happens.

The URL for the health check should be http://localhost:8080/check/health, not /check/status.

It is depends on the Spring-Boot version. After version 2.0 the path name is manage, so your right url is: http://localhost:8080/check/health
You can also change that with (.yml version):
management:
context-path: /manage
security:
enabled: false

Related

Spring-Boot-Actuator Endpoint Prometheus not shown correctly

I want to show some metrics using micrometer prometheus in combination with the spring-boot-actuator. My project is totally based on spring-boot and has the actuator feature enabled and mapped on the following url: http://localhost:9000/actuator
Other endpoints are shown correctly but the http://localhost:9000/actuator/prometheus isnĀ“t. Below you find a screenshot that I get when accessing this http-endpoint.
Can anybody help me? Why is this happening and how do i fix it?
Cause normally prometheus is configured automatically for spring-boot-actuator when you provide the suitable dependency.
you need to check many things to be sure to enable Prometheus by Actuator
First thing you should put the following dependency on your pom.xml to enable Prometheus on your project.
<!-- enable prometheus-->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>1.10.2</version>
</dependency>
The second point you must check if the actuator exists on your
project or not if doesn't exist, you need to add the following
dependency.
<!--to enable actuator help to trace project-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
You need to add the following scripts to your application.yml to
enable the actuator and Prometheus by actuator.
.
management:
security:
enabled: false
server:
port: 9000
endpoint:
metrics:
enabled: true
prometheus:
enabled: true
health:
show-details: always
show-components: always
probes:
enabled: true
shutdown:
enabled: true
info:
env:
enabled: true
enabled: true
endpoints:
web:
exposure:
include: prometheus, metrics, info, health, shutdown, beans
using the above script the actuator will run on port 9000 and you can send a request to the following URL to access the actuator.
http://localhost:9000/actuator/prometheus
and the following URL to access Prometheus
http://localhost:9000/actuator/prometheus
Note: you must check where you are writing your script because I was confused between endpoint and endpoints
The endpoint to set the actuator config.
The endpoints to set the actuator URLs endpoint
Note: you can delete the port from application.yml and the actuator will run by current application port
best luck
This is auto-cofigured by default, here are some pointers for troubleshooting:
Check if you added micrometer-registry-prometheus (without defining the version, the version should come from the BOM)
Check if the actuator endpoint is enabled: management.endpoints.web.exposure.include=*
Check if there is a controller that maps the path of the prometheus endpoint or any of its sub-paths (/, /actuator, /actuator/prometheus)
Check if you browser tricks you curl localhost:9090/actuator/prometheus
ok i solved it with the solution:
i created a bean of type prometheusMeterRegistry manually and so spring boot didn't configure it automatically leading to no metrics provided at the prometheus endpoint
see below code snippet for further details:
// #Bean
// public PrometheusMeterRegistry prometheusMeterRegistry() {
// return new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
// }
In my case I was trying to set up prometheus on old project where was MetricsAutoConfiguration excluded. So removing exclude solved the problem.
#EnableAutoConfiguration(exclude = { MetricsAutoConfiguration.class})

The Spring url to get all request mappings does not work (anymore)

Usually I could get a url mapping overview using the url:
/application/mappings
Now I get a
PageNotFound - No mapping found for HTTP request with URI [/application/mappings] in my log and Response Status: 404 (Not Found) in my browser.
Also the other Spring urls /application/autoconfig, /application/beans and /application/configprops give the same problem.
I'm using spring-boot 2.0.0.RELEASE.
The actuator artifact was added to the pom:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
What am I doing wrong?
According to the current Spring Boot 2.0 documentation the default actuator endpoints are prefixed with /actuator, not with /application. This was different for M4 and I think they've changed it in M7.
M4 docs:
For example, by default, the health endpoint will be mapped to
/application/health.
M7 docs:
For example, by default, the health endpoint is mapped to
/actuator/health

Spring-boot actuator: only some endpoints work

I'm trying to implement spring-boot actuator for the first time but I've noticed that:
It only works if I specify the version, otherwise not;
Only a few endpoints works among those declared by the /actuator endpoint response.
This is the dependencies I've inserted in my pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>1.4.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator-docs</artifactId>
</dependency>
...
</dependencies>
This is my application.properties:
#info for Spring Boot Actuator
info.app.name=Spring Sample Application
info.app.description=Application to demonstrate Spring REST HATEOAS and Actuator
info.app.version=1.0.0
When I make this http request:
http://localhost:8080/actuator
it returns me:
{"links":[{"rel":"self","href":"http://localhost:8080/actuator"},{"rel":"loggers","href":"http://localhost:8080/loggers"},{"rel":"env","href":"http://localhost:8080/env"},{"rel":"info","href":"http://localhost:8080/info"},{"rel":"heapdump","href":"http://localhost:8080/heapdump"},{"rel":"mappings","href":"http://localhost:8080/mappings"},{"rel":"metrics","href":"http://localhost:8080/metrics"},{"rel":"configprops","href":"http://localhost:8080/configprops"},{"rel":"autoconfig","href":"http://localhost:8080/autoconfig"},{"rel":"beans","href":"http://localhost:8080/beans"},{"rel":"auditevents","href":"http://localhost:8080/auditevents"},{"rel":"trace","href":"http://localhost:8080/trace"},{"rel":"health","href":"http://localhost:8080/health"},{"rel":"dump","href":"http://localhost:8080/dump"},{"rel":"docs","href":"http://localhost:8080/docs"}]}
Among these links, only /health and /info seem to work.
In fact, when I ask for /health it returns:
{"status":"UP"}
When I ask for /info it returnes:
{"app":{"description":"Application to demonstrate Spring REST HATEOAS and Actuator","name":"Spring Sample Application","version":"1.0.0"}}
How comes that all the other endpoints gives me Whitelabel error page?
Did you try to see the logs when you try other endpoints. It says
Full authentication is required to access actuator endpoints. Consider adding Spring Security or set 'management.security.enabled' to false.
I guess this is self explanatory. Configure atleast basic auth or set the above mentioned property to false.
Whitelabel error page that you see also says
There was an unexpected error (type=Unauthorized, status=401).
Here is the link for the doc related to this.
In my case I was getting 404 Whitelabel Error Page because only /actuator/health and /actuator/info are the only endpoints enabled by default (as mentioned on the Spring Boot Actuator documentation)
To enable the other endpoints I ended up adding this configuration to my application.yml:
management:
endpoints:
web:
exposure:
include: info, health, loggers, logfile, configprops
I found a posting at Baeldung where it says
Unlike in previous versions, Actuator comes with most endpoints disabled. (Link)
So add management.endpoints.web.exposure.include=*. to your application.properties.

spring boot 1.3.1 devtools hot reload not work if your project name is spring-boot

Spring boot 1.3.1.RELEASE, used devtools.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
Now I add some code in controller method, e.g.
logger.info("delete {} ", name);
but in eclipse console, nothing output, and access this url , the new add logger did not output. So why is so? why hot reload not work?
I found something could explain this phenomenon. Because my project name is spring-boot, and run Application class in eclispe you could see:
you could see after Application name appended (1)
I don't know what's this mean.
After rename project name to anything else(e.g. spring-boot-reservation), now I found devtools could work normally.
And this time the number after Application name is changed to 2,

Spring-Social-facebook + Spring MVC integration

I am trying to access facebook data via spring social facebook integration using the instructions provided at http://spring.io/guides/gs/accessing-facebook.
But currently i am facing 2 type of problem
When i run example as mentioned in tutorial i get following error
No matching bean of type [org.springframework.social.facebook.api.Facebook] found for dependency
When i run this with #Configuration on FacebookConfig class, i get below mentioned error
A ConnectionFactory for provider 'facebook' has already been registered
Is there a workaround to it?
I have kept the war file with source code at https://skydrive.live.com/redir?resid=EA49CD7184E0E40!168&authkey=!AIkoKKx5-Um8AQE
What version are you using?
Try using the version 1.1.0.RELEASE
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-facebook</artifactId>
<version>1.1.0.RELEASE</version>
</dependency>
If it not works, please try post the stacktrace printed.
You need to create a the beans to your class, please post more information like your pom.xml and your spring context configuration.
Ihad the same problem. Spring Social Facebook will automatically add connection factory based on the configuration in application.properties. This auto-configured connection factory is clashing with the one that you're trying to add. Try just to remove your connection factory you add through addConnectionFactories.
Try to use different setting to load your custom connection factory...
E.g. Instead of using OOTB keys use different keys:
#Facebook Social App Details:
# Commented below 2 OOTB Keys & Bingo it worked.
#spring.social.facebook.appId=APP_ID
#spring.social.facebook.appSecret=APP_SECRET
facebook.app.id=APP_ID
facebook.app.secret=APP_SECRET
This will resolve your problem.

Resources