Spring Boot actuator healthcheck not found - spring-boot

Spring Boot 2.3.8 here. My application.yml:
server:
port: 9200
error:
whitelabel:
enabled: false
ssl:
enabled: false
spring:
cache:
type: none
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://${db.hostAndPort}/${db.name}?useSSL=false&nullNamePatternMatchesAll=true&serverTimezone=UTC
username: ${db.username}
password: ${db.password}
testWhileIdle: true
validationQuery: SELECT 1
jpa:
show-sql: false
database-platform: org.hibernate.spatial.dialect.mysql.MySQL5InnoDBSpatialDialect
hibernate:
ddl-auto: none
naming:
physical-strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
implicit-strategy: org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
properties:
hibernate.dialect: org.hibernate.dialect.MySQL5Dialect
hibernate.cache.use_second_level_cache: false
hibernate.cache.use_query_cache: false
hibernate.generate_statistics: false
hibernate.hbm2ddl.auto: validate
management:
port: 9200
endpoint:
health:
show-details: always
endpoints:
web:
exposure:
include: prometheus
I then wrote my own custom HealthIndicator impl:
#Component
#Slf4j
public class MyAppHealthIndicator implements HealthIndicator {
#Override
public Health health() {
Health.Builder health = Health.up();
return health.build();
}
}
When I run my app, it starts up just fine. But when I go to run a curl against the health check endpoint:
$ curl -k -i -H "Content-Type: application/json" -X GET http://localhost:9200/actuator/health
HTTP/1.1 404
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Frame-Options: DENY
Content-Type: application/json
Transfer-Encoding: chunked
Date: Sun, 31 Jan 2021 01:30:39 GMT
{"timestamp":"2021-01-31T01:30:39.206+00:00","status":404,"error":"Not Found","message":"","path":"/actuator/health"}
Have I forgotten a step? Do I need to add anything? Anything wrong with my YAML file? Why can't it find my health check url?

You don't need a custom MyAppHealthIndicator class as Spring Boot comes with a default health indicator which is actived by default via the Endoint /actuator/health/
You're problem is the application.yml configuration where you define that you only want to expose the prometheus endpoint. But you should enable also the health endpoint:
...
endpoints:
web:
exposure:
include: health, prometheus
...
Now you can access it via: http://localhost:9200/actuator/health/
For more details see the offical docs: https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-features.html#production-ready-endpoints

Related

Spring boot config server does not refresh if I update local

I have Spring cloud project which has below information:
Controller of address-service-1:
#RestController
#RequestMapping("/api/address")
#Slf4j
#RefreshScope
public class AddressController {
#Value("${scope-refresh-testing}")
private String message;
#RequestMapping("/scope-refresh-testing-message")
String getMessage() {
return this.message;
}
}
bootstrap.yml of address-service-1:
spring:
application:
name: address-service-1
# register to config server
cloud:
config:
discovery:
enabled: true
service-id: config-server-1
profile: default
management:
endpoints:
web:
exposure:
include:
- refresh
Properties of config-server-1:
server:
port: 8888
spring:
application:
name: config-server-1
cloud:
config:
server:
git:
default-label: master
uri: file:///E:/workspace/Spring-boot-microservices-config-server-study/
Properties which I stored in file:///E:/workspace/Spring-boot-microservices-config-server-study/ (address-service-1.yml):
scope-refresh-testing: testDefault
If I change scope-refresh-testing: testDefault222 then run url actuator/refresh, the properties file will rollback to scope-refresh-testing: testDefault
Did I miss something in configuration?
Thanks

Spring Cloud Config Server/Client Security Issue

I have following security configs in
Server application.yml
management:
security:
enabled: false
server:
port: 8888
spring:
cloud:
config:
server:
jdbc:
order: 1
sql: SELECT prop_key,value FROM xlabs.properties where application=?
and profile=? and label=?
datasource:
password: XXXXX
url: jdbc:postgresql://localhost:8000/finos?currentSchema=xlabs
username: XXXXX
profiles:
active: jdbc
security:
user:
name: mufg
password: mufg
In Client side.
client application.properties
server:
port: 8082
spring:
application:
name: config-server
cloud:
config:
label: latest
profile: development
uri: http://localhost:8888
username: mufg
password: mufg
With this settings
Config server security works fine I can access properties via http://localhost:8888/config-server/development/latest after entering username and passwords. But when I try to up client it says property not resolved. Any issue here?
Thanks.
After some times I am able to find out the answer. In Config server with only that configs the client side will be blocked. So have to disable csrf and allow any request like as follows.
just add sever side.
#Configuration
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
#Override
public void configure(HttpSecurity http) throws Exception {
http
.csrf()
.disable()
.httpBasic()
.and()
.authorizeRequests()
.antMatchers("/encrypt/**").authenticated()
.antMatchers("/decrypt/**").authenticated();
}
}
But Here default security will be disabled. Here problem is if username or password changed from client side authentication happens.

Why does SSL not work for my Spring Boot application?

I'm trying to get SSL to work. I have generated my SSL file .p12 and now I have writen in the configuration inside my application.yml.
Still the port 8080 is used. Why?
server:
port: 8443
ssl:
key-store: classpath:myFile.p12
key-store-password: myPassword
key-store-type: PKCS12
key-alias: mySSLAlias
key-password: myPassword
And the terminal output:
Tomcat started on port(s): 8080 (http) with context path ''
So I can only still connect http://localhost:8080, not https://localhost:8443
Why?
I'm using Spring Security as well.
#Configuration
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
#Override
public void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.antMatchers("/Intranet/AdminCrudView", "/Intranet/Bokning").authenticated()
.antMatchers("/**", "/Intranet**").permitAll()
.anyRequest().authenticated()
.and().logout().logoutSuccessUrl("/").permitAll()
.and()
.oauth2Login().defaultSuccessUrl("/Intranet");
}
}
Here is my complete application.yml file:
spring:
datasource:
driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/spektrakonhemsida?serverTimezone=CET&createDatabaseIfNotExist=true
username: myUser
password: myPassword
jpa:
database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
show-sql: false
hibernate:
ddl-auto: update
security:
oauth2:
client:
registration:
facebook:
clientId: myID
clientSecret: mySecret
accessTokenUri: https://graph.facebook.com/oauth/access_token
userAuthorizationUri: https://www.facebook.com/dialog/oauth
tokenName: oauth_token
authenticationScheme: query
clientAuthenticationScheme: form
resource:
userInfoUri: https://graph.facebook.com/me
mail:
host: smtp.gmail.com
port: 587
username: myGmail#gmail.com
password: myPassword
properties:
mail:
smtp:
auth: true
starttls:
enable: true
crud:
adminfacebookemail: myFacebookEmail#outlook.com
vaadin:
productionMode: true
server:
port: 8443
ssl:
key-store: classpath:mySSLFile.p12
key-store-password: myPassword
key-store-type: PKCS12
key-alias: myAlias
key-password: myPassword
Solved it!
It cannot be
server:
port: 8443
ssl:
key-store: classpath:mySSLFile.p12
key-store-password: myPassword
key-store-type: PKCS12
key-alias: myAlias
key-password: myPassword
It must be two less spaces, like this:
server:
port: 8443
ssl:
key-store: classpath:mySSLFile.p12
key-store-password: myPassword
key-store-type: PKCS12
key-alias: myAlias
key-password: myPassword

virtualHost Not Creating on RabbitMQ server using application.yml springboot and from config server

Virtualhost are not getting created on RabbitMQ server based on configuration
Do i have make sure VH aka Virtual Hosts on RabbitMQ .
Am i missing some configuration.
Please find the configuration below
application.yml
spring:
rabbitmq:
host: 127.0.0.1
virtual-host: /defaultVH
username: defaultUser
password: defaultPassword
cloud:
stream:
bindings:
saviyntSampleQueueA:
binder: rabbit-A
contentType: application/x-java-object
group: groupA
destination: saviyntSampleQueueA
saviyntSampleQueueB:
binder: rabbit-B
contentType: application/x-java-object
group: groupB
destination: saviyntSampleQueueB
binders:
rabbit-A:
defaultCandidate: false
inheritEnvironment: false
type: rabbit
environment:
spring:
rabbitmq:
host: 127.0.0.1
virtualHost: /vhA
username: userA
password: paswdA
port: 5672
connection-timeout: 10000
rabbit-B:
defaultCandidate: false
inheritEnvironment: false
type: rabbit
environment:
spring:
rabbitmq:
host: 127.0.0.1
virtualHost: /vhB
username: userB
password: paswdB
port: 5672
connection-timeout: 10000
bootstrap.yml
############################################
# default settings
############################################
spring:
main:
banner-mode: "off"
application:
name: demo-service
cloud:
config:
enabled: true #change this to use config-service
retry:
maxAttempts: 3
discovery:
enabled: false
fail-fast: true
override-system-properties: false
server:
port: 8080
Added default spring boot added Enable binding
#EnableBinding({MessageChannels.class})
#SpringBootApplication
public class Configissue1124Application {
public static void main(String[] args) {
SpringApplication.run(Configissue1124Application.class, args);
}
}
Now simple straightforward massage channel to to dispatch massage
interface MessageChannels {
#Input("saviyntSampleQueueA")
SubscribableChannel queueA();
#Input("saviyntSampleQueueB")
SubscribableChannel queueB();
}
When i ran the Boot Application its not creating any Virtualhost on the system . i tried using config server buy providing same configuration but still no luck
can you please find if some thing am missing.
Thanks in Advance
The AMQP protocol (or RabbitMQ REST API) provides no mechanism to provision virtual hosts from the client.
Virtual hosts must be provisioned manually on the server.

Spring cloud with Eureka, Oauth2 and zuul

I am trying to configure the sample https://github.com/dsyer/spring-security-angular/tree/master/oauth2/ui to use eureka for the userAuthorizationUri part but with no luck so far. my oauth2 server is registered via eureka
server:
port: ${PORT:${SERVER_PORT:0}}
debug:
security:
user:
password: none
zuul:
routes:
resource:
path: /resource/**
url: http://localhost:9000/resource
user:
path: /user/**
serviceId: authentication-service/uaa/user
spring:
application:
name: ui-service
oauth2:
sso:
home:
secure: false
path: /,/**/*.html
client:
accessTokenUri: http://authentication-service/uaa/oauth/token
userAuthorizationUri: http://authentication-service/uaa/oauth/authorize
clientId: acme
clientSecret: acmesecret
resource:
serviceId: ${PREFIX:}resource
jwt:
keyValue: |
-----BEGIN PUBLIC KEY-----
MYKEY
-----END PUBLIC KEY-----
logging:
level:
org.springframework.security: DEBUG
eureka:
instance:
metadataMap:
instanceId: ${spring.application.name}:${spring.application.instance_id:${random.int(10000)}}
client:
serviceUrl:
defaultZone: http://localhost:8888/eureka/

Resources