I am trying to expose the /actuator/health endpoint in my spring-boot application, but my log states that zero endpoints are exposed. I have seen some documentation that states that the health endpoint is the only endpoint that is enabled by default but it returns 404 for me.
Log from startup of application:
{"#timestamp":"2022-06-29T09:50:59.441+02:00","#version":1,"message":"Exposing 0 endpoint(s) beneath base path '/actuator'","logger_name":"org.springframework.boot.actuate.endpoint.web.EndpointLinksResolver","thread_name":"main","level":"INFO","level_value":20000,"caller_class_name":"org.springframework.boot.actuate.endpoint.web.EndpointLinksResolver","caller_method_name":"<init>","caller_file_name":"EndpointLinksResolver.java","caller_line_number":58}
Accessing /actuator also shows that no endpoints are exposed:
{"_links":{"self":{"href":"http://localhost:8000/actuator","templated":false}}}
I've looked at several other similar posts but none of the fixes provided works for me.
I do have my own endpoint as well in a #RestController that I thought might be interfering, but commenting it out its Post/Get-mappings did not help either.
My pom.xml is as follows:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.6</version>
<relativePath />
</parent>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
In my application.yaml I have tried the following:
server:
port: 8000
management:
health:
probes:
enabled: true
livenessstate:
enabled: true
readinessstate:
enabled: true
endpoint:
health:
probes:
enabled: true
show-details: always
enabled: true
endpoints:
web:
exposure:
include: '*'
enabled-by-default: true
Other settings in the application.yaml (like changing the port) works fine, so I know that the application.yaml is at least being used.
Any ideas?
Since spring-boot 2x these endpoints are disabled and you need to enable them. You can try adding the following to your properties:
endpoints:
enabled: false
health:
enabled: true
I also tried it via
management:
endpoint:
health:
enabled: true
but that didn't work on the platform where I deployed it (WebLogic)
Related
I have a spring data (spring boot and spring cloud) project,and add neo4j starter to it,but in different production environments, I am not sure is neo4j installed.
I use neo4j 3.5,and add dependence:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-neo4j</artifactId>
</dependency>
spring boot is 2.1.8:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.8.RELEASE</version>
<relativePath/>
</parent>
A repository:
public interface UseRepository extends Neo4jRepository<Use, String> {
}
in the application.yml:
spring:
profiles:
active: ${activeProfiles:dev}
data:
neo4j:
uri: bolt://localhost:7687
username: neo4j
password: neo4j
open-in-view: false
Then in a service,I can use the repository:
Iterable<Use> uses = useRepository.findAll();
I can launch the project if no neo4j installed,but if I call any method of any other service with a #Transactional, it will throw a exception Could not open Neo4j Session for transaction,seems the whole project not work.How to make other service class work even neo4j is down?
I have a spring boot microservice with kubernetes dependencies for configmap and secret support.The current spring boot version is 2.3.9.RELEASE . and the kubernetes dependency version is 1.1.0.RELEASE . its an old one , so i tried to update the dependency to its latest 1.1.10.RELEASE.
This is the updated pom details
<spring-cloud-kubernetes.version>1.1.10.RELEASE</spring-cloud-kubernetes.version>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-kubernetes-dependencies</artifactId>
<version>${spring-cloud-kubernetes.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-kubernetes-dependencies</artifactId>
<version>${spring-cloud-kubernetes.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
After updating the kubernetes dependency version to 1.1.10.RELEASE , am getting the below error while stating the app
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'propertyChangeWatcher' defined in class path resource [org/springframework/cloud/kubernetes/config/reload/ConfigReloadAutoConfiguration$ConfigReloadAutoConfigurationBeans.class]: Unsatisfied dependency expressed through method 'propertyChangeWatcher' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'configurationUpdateStrategy' defined in class path resource [org/springframework/cloud/kubernetes/config/reload/ConfigReloadAutoConfiguration$ConfigReloadAutoConfigurationBeans.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.kubernetes.config.reload.ConfigurationUpdateStrategy]: Factory method 'configurationUpdateStrategy' threw exception; nested exception is java.lang.IllegalArgumentException: Restart endpoint is not enabled
This is my bootstrap.yml file
spring:
cloud:
kubernetes:
reload:
enabled: true
monitoring-config-maps: true
mode: polling
period: 15000
strategy: restart_context
config:
enabled: true
sources:
- name: demo
secrets:
enabled: true
enable-api: true
sources:
- name: demo-secret
management:
endpoint:
restart:
enabled: true
health:
enabled: true
info:
enabled: true
env:
enabled: true
refresh:
enabled: true
This is my application.yml file
management:
endpoints:
beans:
enabled: false
web:
exposure:
include: prometheus,info,refresh,health,env,restart
prometheus:
path: /api/actuator/prometheus
sensitive: false
I have enabled the restart endpoint , but still its not working . Please help me on this .
I tried the below way also , but still throwing the same issue.
<properties>
<spring.cloud-version>Hoxton.SR12</spring.cloud-version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring.cloud-version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
I have several Spring Boot apps deployed to Heroku. I have the following services registered with Eureka:
configserver
eureka-server
gateway
uaa
The configserver, gateway and uaa registers themselves, but it registers itself with Eureka but not rightly. When I executed the request to the gateway (POST https://APP_NAME.herokuapp.com/auth/login), the response is Uaa service 503 Service Unavailable.
Gateway Log:
- heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/auth/login"
- DynamicServerListLoadBalancer for client uaa initialized:
DynamicServerListLoadBalancer:{NFLoadBalancer:name=uaa,current list
of Servers=[IP_ADDRESS:PORT],Load balancer stats=Zone stats:
{defaultzone=[Zone:defaultzone; Instance count:1; Active connections
count: 0; Circuit breaker tripped count: 0; Active connections per
server: 0.0;]
- Server stats: [[Server:IP_ADDRESS:PORT; Zone:defaultZone; Total
Requests:0; Successive connection failure:0; Total blackout
seconds:0; Last connection made:Thu Jan 01 00:00:00 UTC 1970; First
connection made: Thu Jan 01 00:00:00 UTC 1970; Active
Connections:0; total failure count in last (1000) msecs:0; average
resp time:0.0; 90 percentile resp time:0.0; 95 percentile resp
time:0.0; min resp time:0.0; max resp time:0.0; stddev resp time:0.0]
This is my configuration for Eureka-server:
application-prod.yml
eureka:
instance:
hostname: ${DOMAIN_NAME}
status-page-url-path: ${management.endpoints.web.base-path}/info
health-check-url-path: ${management.endpoints.web.base-path}/health
lease-renewal-interval-in-seconds: 5
lease-expiration-duration-in-seconds: 10
metadata-map:
profile: ${spring.profiles.active}
version: #project.version#
git-version: ${git.commit.id.describe:}
git-commit: ${git.commit.id.abbrev:}
git-branch: ${git.branch:}
client:
fetch-registry: false
register-with-eureka: false
instance-info-replication-interval-seconds: 10
registry-fetch-interval-seconds: 10
service-url:
defaultZone: http://admin:${spring.security.user.password}#${eureka.instance.hostname}:${server.port}/eureka/
This is my configuration for Uaa:
application-prod.yml
eureka:
client:
service-url:
defaultZone: ${application.register.discovery-url}/eureka/
instance-info-replication-interval-seconds: 10
registry-fetch-interval-seconds: 10
instance:
hostname: ${DOMAIN_NAME:localhost}
appname: uaa
prefer-ip-address: true
instanceId: uaa:${spring.application.instance-id:${random.value}}
status-page-url-path: ${management.endpoints.web.base-path}/info
health-check-url-path: ${management.endpoints.web.base-path}/health
lease-renewal-interval-in-seconds: 5
lease-expiration-duration-in-seconds: 10
metadata-map:
profile: ${spring.profiles.active}
version: #project.version#
git-version: ${git.commit.id.describe:}
git-commit: ${git.commit.id.abbrev:}
git-branch: ${git.branch:}
This is my configuration for Gateway:
application-prod.yml
eureka:
client:
service-url:
defaultZone: ${application.register.discovery-url}/eureka/
instance-info-replication-interval-seconds: 10
registry-fetch-interval-seconds: 10
instance:
hostname: ${DOMAIN_NAME:localhost}
appname: gateway
prefer-ip-address: true
instance-id: gateway:${spring.application.instance-id:${random.value}}
status-page-url-path: ${management.endpoints.web.base-path}/info
health-check-url-path: ${management.endpoints.web.base-path}/health
lease-renewal-interval-in-seconds: 5
lease-expiration-duration-in-seconds: 10
metadata-map:
profile: ${spring.profiles.active}
version: #project.version#
git-version: ${git.commit.id.describe:}
git-commit: ${git.commit.id.abbrev:}
git-branch: ${git.branch:}
POM all services:
Eureka clients and server:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Hoxton.SR4</spring-cloud.version>
</properties>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Only Eureka server:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
Uaa and gateway connection was never established, I guess the problem is when registering eureka-clients with eureka. Also I have try modifing this property eureka.instance.prefer-ip-address: false and the eureka-clients are registers as APP_NAME.herokuapp.com:PORT which makes it either non-discoverable or unable to lookup or call other registered services.
NOTE:
All service alrady registered with eureka server
eureka.instance.prefer-ip-address: false
list of Servers=[APP_NAME.herokuapp.com:PORT] of ribbon.
eureka.instance.prefer-ip-address: true
list of Servers=[IP_ADDRESS:PORT] of ribbon
DOMAIN_NAME = APP_NAME.herokuapp.com for all services.
I execute ping to IP_ADDRESS and no response
I have Use Account Heroku for test.
I am unable to get the value I am expecting, An exception is thrown at this line #Value("${message:this-is-class-value}").
SERVER SIDE
pom.xml
<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.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
</dependencies>
src/main/resources/application.properties
server.port=8888
spring.application.name=config-service
spring.cloud.config.server.git.uri=file:///C:/config
management.endpoints.web.exposure.include=*
spring.security.user.name=root
spring.security.user.password=abc123
Application class
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
#SpringBootApplication
#EnableConfigServer
public class ConfigServiceApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServiceApplication.class, args);
}
}
Local git folder
Configurations files with the same property but the different value to detect
c:/config/application.properties
c:/config/api-gateway.properties
c:/config/api-gateway-PROD.properties
output while server startup
Completed initialization in 5 ms
WARN : Could not merge remote for master remote: null
INFO : o.s.c.c.s.e.NativeEnvironmentRepository : Adding property source: file:/C:/config/application.properties
if I access this url
http://localhost:8888/api-gateway/PROD
console output is as follows
WARN : Could not merge remote for master remote: null
INFO : o.s.c.c.s.e.NativeEnvironmentRepository : Adding property source: file:/C:/config/api-gateway-PROD.properties
INFO : o.s.c.c.s.e.NativeEnvironmentRepository : Adding property source: file:/C:/config/api-gateway.properties
INFO : o.s.c.c.s.e.NativeEnvironmentRepository : Adding property source: file:/C:/config/application.properties
CLIENT SIDE (Separate Project)
pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
Application class
#SpringBootApplication
#EnableZuulProxy
#EnableDiscoveryClient
public class ApiGatewayApplication {
public static void main(String[] args) {
SpringApplication.run(ApiGatewayApplication.class, args);
}
}
Controller
#RestController
public class SettingsController {
#Value("${message:this-is-class-value}")
String name = "World";
#RequestMapping("/")
public String home() {
return "Hello " + name;
}
}
resources/application.yml
server:
port: 8282
spring:
application:
name: api-gateway
eureka:
instance:
preferIpAddress: true
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}
resources/bootstrap.yml
spring:
profiles:
active: PROD
cloud:
config:
name: api-gateway
uri: http://localhost:8888/
username: root
password: abc123
management:
endpoints:
web:
exposure:
include: refresh
Console output
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'settingsController': Injection of autowired dependencies failed; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.util.LinkedHashMap<?, ?>] to type [java.lang.String]
Caused by: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.util.LinkedHashMap<?, ?>] to type [java.lang.String]
Please do let me know if anything else is required.
add message=Hello from property file1 in src/main/resources/application.properties. Or if you want to read this property from c:/config/application.properties or c:/config/config-service.properties you need to configure external configuration file by using #ConfigurationProperties annotation.
Looks, you are trying to use the #Value annotation on controller class which resides in your Cloud config server application. While the concept is like cloud config server application will be the provider to other applications and it can provide the properties from git or local file system (configuration) to requester client application. Other applications will connect to your config server application by providing it's URL, application name and profile for which it want to get the properties. You can check below URL for cloud config server and client application.
https://www.thetechnojournals.com/2019/10/spring-cloud-config.html
Your cloud config server has security configuration as below.
spring.security.user.name=root
spring.security.user.password=abc123
You client configuration doesn't provide any security configuration which is causing 401 error in your logs.
To solve this issue please do below changes to your client configuration.
Client configuration:
spring:
profiles:
active: PROD
cloud:
config:
name: api-gateway
uri: http://localhost:8888/
username: root
password: abc123
I'm using Spring Boot 2.0.1 and the Spring cloud dependencies are imported from:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.RC1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
I believe that the dependencies of interest are these:
<dependencies>
...
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-binder-rabbit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-reactive</artifactId>
</dependency>
...
</dependencies>
In my application.yaml I've added multiple consumer bindings:
spring:
cloud:
stream:
bindings:
input1:
bindingRoutingKey: key1.#
binder: rabbit
group: group1
destination: dest-group1
transacted: true
input2:
bindingRoutingKey: key2.#
binder: rabbit
group: group2
destination: dest-group2
transacted: true
I've read for example here that one should add requiredGroups to the producer(s) in order to create the queues and bindings automatically. However my application doesn't produce any messages, it just consumes messages published by other application so I don't have any producers defined. I've tried to modify the application.yaml file to just add a dummy producer:
spring:
cloud:
stream:
bindings:
dummyProducer:
producer:
requiredGroups: group1,group2
input1:
bindingRoutingKey: key1.#
binder: rabbit
group: group1
destination: dest-group1
transacted: true
input2:
bindingRoutingKey: key2.#
binder: rabbit
group: group2
destination: dest-group2
transacted: true
But this doesn't work. So my question is:
How should I modify my application.yaml file (and possible the code if required) to make the Spring Cloud stream create the queues and bindings on startup?
We normally only provision the exchange on the producer side; we don't provision queues unless required-groups is set.
On the consumer side, we always provision queues (and the exchange).
If that is not happening, something else is wrong; do you have #EnableBinding?
Show your application code.