Actuator endpoint not showing up - spring-boot

I am trying to add prometheus into my spring boot project. I am using spring boot actuator to expose the metrics endpoint . Did everything following tutorials but I keep on getting a 404 error. I also tried every single solution given in:
Unable to access Spring Boot Actuator "/actuator" endpoint
and
Spring Boot 2 - Actuator Metrics Endpoint not working
My dependecies:
<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>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
<version>1.7.0</version>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>1.7.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-hal-explorer</artifactId>
<version>3.5.1</version>
</dependency>
context.xml (external properties):
<Parameter name="management.endpoints.web.exposure.include" value="*"/>
<Parameter name="management.security.enabled" value="false"/>
<Parameter name="management.endpoints.beans.enabled" value="false"/>
<Parameter name="endpoints.actuator.enabled" value="true"/>
<Parameter name="management.endpoints.web.base-path" value="/actuator"/>

It looks like you missing configuration in your application.yml file (If you use the application.properties file try to change code format):
management:
endpoint:
health:
show-details: always
endpoints:
web:
exposure:
include: '*'
metrics:
export:
prometheus:
enabled: false
I hope that's help you

Related

spring boot tomcat access logs log4j2 elastic common schema

Configuring spring boot to use log4j2 and the ECS was simple enough. All we needed to do was include the following dependencies in our pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
<groupId>co.elastic.logging</groupId>
<artifactId>log4j2-ecs-layout</artifactId>
<version>1.0.1</version>
</dependency>
Then in the log4j2.xml file we just needed to include something like this:
<Console name="prod" target="SYSTEM_OUT">
<EcsLayout serviceName="${service-name}" stackTraceAsArray="true" includeOrigin="true" includeMarkers="true" />
</Console>
However, when we configure spring boot to log the application access logs in application.yml we do this:
server:
tomcat:
accesslog:
enabled: true
encoding: UTF-8
directory: /dev
prefix: stdout
buffered: false
suffix:
file-date-format:
pattern: "ACCESS_LOG: %h %l %u \"%{yyyy-MM-dd HH:mm:ss.SSS}t\" \"%r\" status=%s size=%b \"user-agent=%{User-Agent}i\""
The access logs are not logged as json with the EcsLayout.
How can I configure a spring boot application to log tomcat access logs as json to the console using the elastic common schema (json) format?

Spring boot server startup issue elastic search

I am using elasticsearch7.5. I have turned on the following properties
xpack.security.enabled: true
xpack.security.authc.api_key.enabled: true
I have generated API keys to connect our springboot to elasticsearch.I am using
spring-boot-starter-data-elasticsearch
All my requests are from "RestHighClient" and able to trigger the requests.Only problem is during server startup, they are some errors where it is not able to connect to Elasticsearch.
org.elasticsearch.transport.RemoteTransportException: [ADMIN-PC][127.0.0.1:9300][cluster:monitor/nodes/liveness]
Caused by: org.elasticsearch.ElasticsearchSecurityException: missing authentication credentials for action [cluster:monitor/nodes/liveness]
In pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>6.8.3</version>
</dependency>
in application properties:
spring.elasticsearch.server=localhost:9200
spring.data.elasticsearch.cluster-name=elasticsearch
spring.data.elasticsearch.cluster-nodes=127.0.0.1:9300
spring.data.elasticsearch.repositories.enabled=true
Can someone suggest me ,How I can fix it.
Remove these lines from your configuration:
spring.data.elasticsearch.cluster-name=elasticsearch
spring.data.elasticsearch.cluster-nodes=127.0.0.1:9300
These make Spring Boot to configure the transport client.

Trouble when changing Spring Boot version from 2.0.3.RELEASE to 2.1.0.BUILD-SNAPSHOT

I have a working code that stops to work when I change Spring Boot version from 2.0.3.RELEASE to 2.1.0.BUILD-SNAPSHOT.
Sometimes the error is:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
***************************
APPLICATION FAILED TO START
***************************
Description:
The bean 'dataSource', defined in BeanDefinition defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class], could not be registered. A bean with that name has already been defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class] and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
or ...
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-07-16 14:38:18.509 ERROR 604 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
The bean 'scopedTarget.oauth2ClientContext', defined in class path resource [org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2RestOperationsConfiguration$SessionScopedConfiguration$ClientContextConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [org/springframework/security/oauth2/config/annotation/web/configuration/OAuth2ClientConfiguration$OAuth2ClientContextConfiguration.class] and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
Both cases it is related to duplicated bean os something else.
My POM dependencies are:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Finchley.BUILD-SNAPSHOT</spring-cloud.version>
<maven.test.skip>true</maven.test.skip>
</properties>
<dependencies>
<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>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-oauth2</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
and the config:
server:
error:
include-stacktrace: always
whitelabel:
enabled: false
servlet:
session:
cookie:
name: HYDRASSESSION
port: 36205
management:
endpoints:
web:
exposure:
include: "*"
security:
basic:
enabled: false
oauth2:
client:
clientId: atlas
clientSecret: secret
accessTokenUri: http://myserverip:36202/oauth/token
userAuthorizationUri: http://myserverip:36202/oauth/authorize
resource:
userInfoUri: http://myserverip:36202/user/me
spring:
jpa:
properties:
hibernate:
temp:
use_jdbc_metadata_defaults: false
hibernate:
ddl-auto: validate
application:
name: atlas
datasource:
password: admin
username: postgres
url: jdbc:postgresql://myserverip:36211/atlas?ApplicationName=Atlas
guardiao:
logout:
path: http://myserverip:36202/exit
It run fine when using 2.0.3.RELEASE but I'm receiving an error when try to login myserver:36202/oauth/authorize?client_id=: by browser complains ERR_TOO_MANY_REDIRECTS but I have no errors in console. Anyway... my question is: how can I update my SpringBoot to 2.1.0.BUILD-SNAPSHOT ?
So as the exception reports, there are two beans of the same type. Historically Spring would override one bean with the other. That has long been an annoyance since you could get hard to find bugs where a second bean with a completely different type, but with the same bean ID would make your first bean vanish.
Spring Boot 2 now disables that sort of bean overriding by default. You can re-enable it by setting the following property in your application.yml:
spring.main.allow-bean-definition-overriding: true
This re-enables the previous behavior. It doesn't address the root cause that beans are being overridden though and also mean you won't get the benefit of bean override errors. Upgrading the underlying libraries will hopefully clean this up over time.
As noted on other comments, upgrading the spring-security-oauth2-autoconfigure dependency to org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:2.1.0.RELEASE may solve it for you.
This answer might be helpful for those who have setup a new project and adding the spring.main.allow-bean-definition-overriding: true property in application.properties file is not fixing the issue:
Check the folder where your application.properties file is present -- it needs to be available directly under the directory: src/main/resources/ and not anywhere else.

Camel Spring Boot Actuator Not Working with cxfrs route

I have developed simple cxfrs based route using springboot+camel, but when i added spring-boot-starter-actuator and running this as #SpringBootApplication:
The Spring Actuator endpoints like /health not working and return http 404.
My Route:
from("cxfrs:http://127.0.0.1:8181?resourceClasses=org.imran.greenfarm.services.OrderService&bindingStyle=SimpleConsumer&providers=#jsonProvider&features=#featuresList")
.to("log:?showAll=true")
.toD("direct:${header.operationName}");
application.properties
# all access to actuator endpoints without security
management.security.enabled = false
# turn on actuator health check
endpoints.health.enabled = true
Update:
if i add spring-boot-starter-web it shows status on http://localhost:8080/health or http://localhost:8080/camel/health.
From logs it shows startup of two different servers jetty and tomcat. Can we configure in such a way that either SpringBoot use "cxf-rt-transports-http-jetty" or Camel cxfrs use SpringBoot Jetty "spring-boot-starter-jetty".
if we provide management.port=8181 in properties it throws port already in used.
You can add springboot jetty by adding following in pom.xml, you have to exclude default tomcat
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>

OrientDB with spring mvc configuration

Please suggest me how can i configure the orientdb with spring mvc.
<bean id="databaseFactory" class="org.ops4j.orient.spring.tx.OrientObjectDatabaseFactory"
p:url="remote:localhost/MyDB" p:username="userName" p:password="pwd" />
<bean id="orTransactionManager" class="org.ops4j.orient.spring.tx.OrientTransactionManager"
p:databaseManager-ref="databaseFactory" />
I have added above code into my mvc-dispacher-servlet.xml file
and i have added dependencies also in to pom.xml
<dependency>
<groupId>org.ops4j.orient</groupId>
<artifactId>orient-spring-tx</artifactId>
<version>0.3.0</version>
</dependency>
<dependency>
<groupId>com.orientechnologies</groupId>
<artifactId>orientdb-core</artifactId>
<version>2.2.13</version>
</dependency>
<dependency>
<groupId>com.orientechnologies</groupId>
<artifactId>orientdb-graphdb</artifactId>
<version>2.2.13</version>
</dependency>
<dependency>
<groupId>com.orientechnologies</groupId>
<artifactId>orientdb-enterprise</artifactId>
<version>2.2.0-beta</version>
</dependency>
My OrientDb server is 2.2.13 version which is latest.
help me in configuring it.if possible suggest a sample project URL also.
Thank You

Resources