Spring Boot Google Cloud Secret Manager - spring

I followed the instruction on setting secret manager with GCP on Spring Boot, I created a secret in Google Cloud, and added the following in application.properties
spring.datasource.password=${sm://DB_PASSWORD}
It didn't work, however, if I used SecretManagerTemplate, I can get the secret by secretManagerTemplate.getSecretString("DB_PASSWORD");
However, I need the datasource password to be initialized at the beginning of the application, has anyone used secret manager in spring boot?

The problem can be solved magically by changing pom.xml from
<properties>
<spring-cloud.version>Hoxton.SR4</spring-cloud.version>
</properties>
to
<properties>
<spring-cloud.version>Hoxton.SR6</spring-cloud.version>
</properties>

Related

Spring boot actuator for commandline runner application

I want to enable actuator for health check in PCF for the non web or batch or commandLineRunner spring boot application.
Could some one please share some details to resolve this issue.
Please let me know if any other details required
I tried the below options
Adding actuator dependency
Adding http and jmx related properties
Since localhost:8081/actuator is not accessible could not view endpoints
How to enable url for non web app
add
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
application.properties
spring.jmx.enabled = true
management.endpoints.jmx.exposure.include=*
management.endpoints.jmx.domain=com.example.demomail
management.endpoints.jmx.unique-names=true
run jconsole find your application name then connect.
find Tab MBeans, find com.example.demomail in left tree.
As far as I understand you need to enable the Actuator endpoints.
You must add the Spring Boot Actuator dependency (as you have already done).
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Then in your application.properties file enable HTTP and JMX support (as you have already done).
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
management.endpoint.jmx.exposure.include=*
Now you will have to push your app to PCF and create a binding to a route to create access for the Actuator endpoint/s.
The URL to access the actuator endpoint will be something like this http://<route-url>/actuator/health
In the command line, I would use something like this to return a list of routes and the URL route of the application.
cf curl /v2/apps/<app-guid>/routes

how to setup the Spring Boot Admin Server via war-deployment in a external tomcat?

I'm trying to set up spring-boot-admin via war deployment. for war i'm not able to see the client application in spring boot admin dashboard.
I've tried with spring boot version 2.1.6 and tomcat version 8.5.47 but i'm not able to see the client application in dashboard.
My client application POM
<version>1.0.0</version>
<packaging>war</packaging>
<name>spring-boot-admin-client</name>
<description>Demo project for Spring Boot Admin - Client</description>
Dependencies I have used:
spring-boot-starter-actuator
spring-boot-admin-starter-client
spring-boot-starter-security
spring-boot-starter-test
spring-boot-starter-web
Not getting any error message but client application i'm not able to see it in spring-boot-admin dashboard.
Have u configured spring.boot.admin.client.instance.service-url property in client application?
Generally when Spring Boot Client is installed on external tomcat, SBA predicts the actuator endpoints path as http://server:port/actuator while the actual path is http://server:port/context-root/actuator.
This is where spring.boot.admin.client.instance.service-url property comes to the rescue. spring.boot.admin.client.instance.service-url should be set as http://server:port/context-root

spring boot refresh the properties files without config server

I want to refresh the properties files in spring boot.
version - 2.1.4.RELEASE
In case of spring config server have to connect all my app to config server which i dont want as our application is in prod and we dont want a bigger change.
Is it possible in the same application i can refresh the prop file using config server if not using config server then using some spring code
can i do it.
NOT application.properties , Have a application-optional.properties outside of project want to refresh only this.
The RefreshEndpoint is provided by Spring Cloud. Adding the spring cloud starter config will get you the required beans and API to refresh.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
Additionally you will need to expose the API via management.endpoints.web.exposure.include="health,info,refresh" or you can use "*" to expose every enabled actuator endpoint to the web.

Hystrix's health endpoint not available

I'm trying to use the Circuit Breaker Pattern with Springboot and Netflix's Hystrix implementation and I'm struggling to access its health endpoint.
The documentation refers it should be available in /hystrix.stream but that's not happening. Also, I've noticed the following error upon theapplication initialisation: Endpoint ID 'hystrix.stream' contains invalid characters, please migrate to a valid format..
Does someone know how to solve this issue or how to change the endpoint name?
Versions:
Springboot 2.1.4.RELEASE
Spring Cloud Greenwich.SR1
Thanks in advance!
You should be able to see something like this in the logs when the server start:
INFO 14451 --- [ost-startStop-1] o.s.b.a.e.web.ServletEndpointRegistrar : Registered '/actuator/hystrix.stream' to hystrix.stream-actuator-endpoint
Try /actuator/hystrix.stream
For spring boot 2.1.x , default endpoint URL for hystrix is /actuator/hystrix.stream
Try to change spring cloud version to Hoxton.RELEASE in pom.xml:
<properties>
<java.version>11</java.version>
<spring-cloud.version>Hoxton.RELEASE</spring-cloud.version>
</properties>

Spring Cloud Bus - Refresh a specific cluster of client

I have a spring cloud config server configured over spring cloud bus over kafka.
I am using Edgware.RELEASE with boot 1.5.9.
When I send a POST request to the endpoint /bus/refresh with destination=clientId:dev:** in the body via POSTMAN to config server, all the clients get their beans refreshed even though their clientId doesn't match the value in the destination field.
Here are additional configuration details:
spring cloud config server
pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-monitor</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-kafka</artifactId>
</dependency>
application.properties
server.port=8888
management.security.enabled=false
spring.cloud.bus.enabled=true
spring.kafka.bootstrap-servers=localhost:9092
I have two config clients with id - config-client1 and config-client2
After changing an application property in the repository for config-client2, I submit a POST request to /bus/refresh endpoint on the config server, with destination=config-client2:dev:** in the body of the request. I was hoping this would refresh/re-initialize the beans only in config-client2 application. But I noticed beans in config-client application are also refreshed/re-initialized. I also noticed config-client application receiving refresh event along with config-client2.
I was hoping only config-client2 application receives the event and its beans are the only ones that are refreshed as a result of it.
Wondering if I am missing any configuration setting to enable granular refresh at specific client level.
I did go through the document posted at - http://cloud.spring.io/spring-cloud-static/Edgware.RELEASE/single/spring-cloud.html, but the results are not as explained.
Any help with a working example is appreciated.
You can use:
curl -X POST http://localhost:8001/actuator/bus-refresh/config-client2
You also need this in your application.properties or .yml.
spring.cloud.config.uri=http://localhost:8001
spring.cloud.config.uri should point to your Spring Config Server

Resources