Spring Profiles Deprecated - spring

How to use inheritance in application.yml settings now?
I have updated to Spring Boot 2.6.7 and notice
spring.profiles is Deprecated
What changes should I make?
...
---
spring:
profiles: <--- Deprecated
default:
- "actuator"
- "swagger"
group:
default:
- "actuator"
- "swagger"
local:
- "local"
- "actuator"
- "logger"
- "swagger"
staging:
- "staging"
- "actuator"
- "logger"
- "swagger"
integration:
- "integration"

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 Config Server : get secrets from vault with specific path

I am trying to get my microservices configuration from a config server connected to 2 sources : git and vault (for secrets). I have the config bellow:
in the config-server:
server:
port: 8888
spring:
profiles:
active: git, vault
cloud:
config:
server:
vault:
port: 8200
host: 127.0.0.1
kvVersion: 2
git:
order: 2
uri: git#gitlab.git
and in the client side in the bootstrap.yml:
spring:
application:
name: my-service-name
cloud:
config:
uri: http://localhost:8888
token: //token
label: dev
But in my vault i have the path like this :
secret/cad
|--my-service-name
When i make my secret directly in /secret/my-service-name i can access my secrets, but how can i configure acces to secrets in : /secret/cad/my-service-name
Thank you.
You can create your Custom configuration Class that implements VaultConfigurer where you can override to your custom path
#Configuration
Public class CustomVaultConfiguraton implements VaultConfigurer {
#override
public void addSecretsBackends(SecretBackendConfigurer configures){
configures.add("customPath");
}
}
add above configuration class in spring.factories
org.springframework.cloud.bootstrap.BootstrapConfiguration=\packagename.CustomVaultConfiguration

spring cloud unable to route to internal application

I am using spring cloud to route application but unable to do so below are the details
Gateway configuration
port: 8080
debug: true
spring:
application:
name: cloud-gateway
cloud:
gateway:
discovery:
locator:
enabled: true
lower-case-senstive: true
routes:
- id: product-composite
uri: localhost:7000
predicates:
- Path: /product-composite/**
eureka:
instance:
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
server:
port: 8761
waitTimeInMsWhenSyncEmpty: 0
response-cache-update-interval: 5000
management.endpoints.web.exposure.include: '*'
Product Composite Service* (I am trying to call)
port: 7000
spring:
application:
name: product-composite
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
initialInstanceInfoReplicationIntervalSeconds: 5
registryFetchIntervalSeconds: 5
register-with-eureka: true
fetch-registery: true
instance:
leaseRenewalIntervalInSeconds: 5
leaseExpirationDurationInSeconds: 5
Path
#RestController
public class ProductCompositeServiceController {
#GetMapping
public String getString() {
return "Hello grom product CompositeController";
}
}
Can you help? If needed I can provide more details
Note: if product-composite-servcie is called without eureka I am getting response but with eureka I am getting
404 Resource not found
Edit
Below is the stacktrace I am getting so far:
2020-06-24 22:22:05.252 DEBUG 38876 --- [or-http-epoll-2] o.s.w.r.handler.SimpleUrlHandlerMapping : [63939523-1] Mapped to ResourceWebHandler ["classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/"]
2020-06-24 22:22:05.255 DEBUG 38876 --- [or-http-epoll-2] o.s.w.r.resource.ResourceWebHandler : [63939523-1] Resource not found
2020-06-24 22:22:05.273 DEBUG 38876 --- [or-http-epoll-2] a.w.r.e.AbstractErrorWebExceptionHandler : [63939523-1] Resolved [ResponseStatusException: 404 NOT_FOUND] for HTTP GET /product-composite/
2020-06-24 22:22:05.281 DEBUG 38876 --- [or-http-epoll-2] o.s.http.codec.json.Jackson2JsonEncoder : [63939523-1] Encoding [{timestamp=Wed Jun 24 22:22:05 IST 2020, path=/product-composite/, status=404, error=Not Found, mess (truncated)...]
2020-06-24 22:22:05.299 DEBUG 38876 --- [or-http-epoll-2] o.s.w.s.adapter.HttpWebHandlerAdapter : [63939523-1] Completed 404 NOT_FOUND
I also tried to add path as
routes:
- id: product-composite
uri: localhost:7000
predicates:
- Path: /product-composite/**
filters:
- RewritePath: /product-composite/(?<segment>.*), /$\{segment}
You don't have a path in your controller. Try
#GetMapping("/product-composite")

Why placeholders in the bootstrap.yml are not resolved?

I'm getting below exception in my Spring project:
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'MY_KEY' in value "${MY_KEY}"
org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:174)
org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:126)
This is how my bootstrap.yml looks like in src/main/resources/
spring:
profiles:
active: native
application:
name: myapp
cloud:
config:
server:
bootstrap: true
health:
enabled: false
encrypt:
# key: ${MY_KEY}
key: ${MY_KEY}
Other placeholders defined in application.yml are resolved correctly.
Following are the dependencies in my project:
spring-boot-starter:1.5.4.RELEASE
spring-cloud-starter-config: -> 1.3.1.RELEASE
spring-cloud-starter:1.2.2.RELEASE
spring-cloud-config-server: -> 1.3.1.RELEASE
spring-cloud-core:1.2.4.RELEASE
spring-cloud-config-client:1.3.1.RELEASE

Spring Cloud kubernetes not loading config map

I have created the 2 config map named personservice and personservice-dev.
I am running spring boot application with profile dev but it is not loading the right config map. This is what I see in logs of the pod which gets crashed.
2019-11-05 16:29:37.336 INFO [personservice,,,] 7 --- [ main] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource {name='composite-configmap', propertySources=[ConfigMapPropertySource {name='configmap.personservice.default'}]}
2019-11-05 16:29:37.341 INFO [personservice,,,] 7 --- [ main] b.c.PropertySourceBootstrapConfiguration : Located property source: SecretsPropertySource {name='secrets.personservice.default'}
2019-11-05 16:29:37.445 INFO [personservice,,,] 7 --- [ main] c.person.PersonMicroServiceApplication : The following profiles are active: kubernetes,dev
Kubectl get configmaps
Deployment file:
apiVersion: apps/v1
kind: Deployment
metadata:
name: personservice
labels:
app: personservice
spec:
replicas: 1
selector:
matchLabels:
app: personservice
template:
metadata:
labels:
app: personservice
spec:
containers:
- name: personservice
image: microservice-k8s/personmicroservice-k8s:1.0
ports:
- containerPort: 8080
env:
- name: PROFILE
value: "dev"
- name: SERVER_PORT
value: "8080"
- name: ZIPKIN_URI
value: "http://172.19.27.145:9411"
Bootstrap:
spring:
application:
name: personservice
You confused things. Your configmap is named personservice-dev and your application's name is personservice not personservice-dev, by default Spring Cloud K8S looks for configmap with name equals to spring.application.name and not spring.application.name-{profile}.
You have 2 ways to solve your problem:
1-Remove personservice-dev and in your personservice configmap:
kind: ConfigMap
apiVersion: v1
metadata:
name: personservice
data:
application.yml: |-
p1:
pa: blabla
---
spring:
profiles: dev
p1:
pa: blibli
---
spring:
profiles: prod
p1:
pa: blublu
2-Keep personservice-dev and personservice and define this in bootstrap.yml:
spring:
cloud:
kubernetes:
config:
name: ${spring.application.name} #This is optional
sources:
- name: ${spring.application.name}-${PROFILE} # Here you get your `personservice-dev` configmap

Resources